If field is disabled, do not require
Is it true, if field is disabled it would be not required (pass validation)?
I have toggle, when toggle is on, field becomes disabled, but still required validation don't let me to pass the field.
21 Replies
Can you share the code for your disabled field?
->requiredIf('toggle',false)
?
But not working
custom page or resource?
Custom Page
in addition default() not working too
in Custom Page
did you do
$this->form->fill()
in the mount method?
are you using statePath()
?yes ofcourse
console errors?
Could you share the whole code?
no error
the whole code?
I have noticed this, @Leandro Ferreira it's usually if you edit a form and have a field required added later and it is empty. It can't continue as it's required even though it's disabled so can't be filled.
do you mean, if you use
disabled()->required()
, required
validation should be ignored?Yep!
It doesn't look like you're actually disabling this field.
I don't see in that code how you're disabling the field when the toggle is changed?
Does that not work?
If the toggle is false, toggleButton should be disabled and its state shouldn't appear in the data array when the form is submitted
toggleButton is requred if toggle is false
disabled when toggle is true
->requiredIf('toggle', false)
should workAh, I assumed from their question that they wanted to actually disable the toggleButtons, not just make it not required.
@Ross Bearman disabled working
Also I noticed
default() not working too
Scenario is if I toggling to On, than I want to disable ToggleButtons, Set value 0 (0 option will add later, this is second challenge, need to hide 0 option for user ) for example, and Validation not required
You should be able to use
afterStateUpdated()
on the Ttoggle
to update the selected item on the ToggleButton
. However if you're using disabled()
, you'll also need to set ->dehydrated(true)
on the ToggleButtons
and use requiredIf('toggle', false)
, otherwise the 0
state won't be returned.
Another option could be to use a Hidden
field to actually return the value and update its value to either 0
or the number selected in the ToggleButton
whenever the state of either is updated.
That way you won't need to deal with hiding the 0
option.Solved
changed to
as @Leandro Ferreira suggested