There is a simple input component binded to form:
<TextArea
readonly={isReadonly}
required
maxlength={160}
{...field(model.addrs)}
/>
The value of textfield is undefined while executing form.read()
If I don’t touch the form and click submit - form fires submit successfully.
If I manually execute await form.validate()
then form.invalid
is false
If I just set focus and blur (don’t edit, just touch) on TextArea component - form.invalid
became true.
I am not able to set validation on backend side as the DTO comes from 3rd party library.
Is it possible to forse form became invalid if no any field touched and user just click submit?
Hi Roman,
I confirm that Hilla validation is based on the information gathered from the Java class being validated, so marking a field as required in the interface has no effect.
But you can add a custom client-side validator to get the effect you’re trying to achieve here.
Anyway, as noted in the linked documentation, you should always make sure that you have proper validation in place on the server, as it is always possible to circumvent client-side validation.
You can either set up an additional validator on the server or use an addtional DTO layer.
Thank you for the reply.
I know about custom validator, but the problem is that form is huge and alot of code I need to write just to make field really required.
Ok, will think.
If the form is huge, please consider another DTO layer with explicit validation as per business requirements of your application. That’s the right thing to do, to protect against wrong data going through.