Livewire component with custom, dynamic form, struggling with select default values
I have this in my livewire component:
The above form is generated dynamically based on user selections in step 1 of a wizard. Step 2 is the above code. However, the default value isn't working on the select.
I've tried adding $this->form->fill() to my render method, but it's not working. Since I don't know how many forms/fields will exist until the user makes a selection, I can't set the defaults inside of $this->form->fill().
In my blade file I have this:
Any ideas?
3 Replies
Still struggling with this, hoping maybe someone has some ideas. This is the current iteration of the offending code. I just can't seem to set a default value for the select:
I've also tried
->afterStateHydrated(fn (Select $component) => $component->state(array_search($defaults['transaction_date'], $options)))
Defaults should be passed through
$this->form->fill()
I thinkYou should add
$this->form->fill()
in the mount method and use a statePath. Check the docs
https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component/#adding-the-form