Why are disabled() fields validated? (e.g. required())
I'm building a workflow app with multiple forms. Sometimes a user can send back to the previous step.
In that case, I only want the user to fill in a reason text field, and use a custom form action to send it back. Not bothering with validation of the rest of the form.
That all works fine, except for the validation part. I reckoned that if I
disabled()
the fields, they would skip validation. I believe that's how standard HTML forms work. But that doesn't seem the case in Filament.
Can I skip validation in some other way?2 Replies
The require() method adds browser validation attributes to the field. You can circumvent this by using ->rules() instead to force server validation only. But the real question is why would a field be required and disabled? Sounds like requiredIf() would be more appropriate.
It indeed does add browser validation using the
required
attribute, but browser validation is skipped when the component is also disabled
. It's server validation that's skill kicking in, including a translated Fieldname X is required
error message.
The only difference between required()
and rules('required')
is that the latter doesn't give me the asterisk*. It still validates disabled fields.
I couldn't get requiredIf()
to work. But you lead me to another solution:
It's not very pretty to include that closure to every required field, but it's working. The whole form stays visible and editable, just the required validation is dropped when sending back.