Setting default value for Checkbox (forms) is not working
I am trying to set a default value for a Checkbox. Basically I am trying to get a value from the database and then based on a specific condition, check/uncheck the box automatically.
Here is the code snippet:
5 Replies
Are you using form builder in a custom livewire component? Did you add
$this->form->fill()
in the mount method?Note that these defaults are only used when the form is loaded without existing data
No. I was doing it inside the inside the resource
So, what to do if I want to set the value based on some saved user value?
For example, if $record->value > 5, check the checkbox, else uncheck
default()
only works in the CreatePage. If you want to use it in the EditPage, I think you can use formatStateUsing()
instead