Closed Muffinman closed 2 years ago
This is because there is no Livewire property associated with these select fields when the form is first loaded, since there is no $type
selected.
So you must add some extra code to the type field to add these properties to the form state, so they aren't missing:
Forms\Components\Select::make('type')
->options(['user_id' => 'User ID', 'customer_id' => 'Customer ID'])
->reactive()
->required()
->afterStateUpdated(fn ($set) {
$set('customer_id', null);
$set('user_id', null);
}),
This ensures that at all times when each select is visible, there is a Livewire property associated with the field. So the console errors will not be present.
Thanks so much. That didn't seem to change anything for me, but I think I understand what you're getting at - I'll keep looking!
Package
filament/forms
Package Version
2.15.19
Laravel Version
9.20
Livewire Version
No response
PHP Version
8.1.9
Problem description
When adding a
searchable()
input inside aschema()
callback\Closure
, it can cause javascript errors and some general weird behaviour.On the JS console we see errors like:
It also seems to fail to send the field state back for these
searchable()
fields when saving. Causing validation error:I'm using a closure to work out the correct configuration fields to render, depending on the user's selection of
type
. I don't want to render ALL the condition fields by default and usehidden()
because we will end up with many condition types here and that could get slow / messy.I want this config to be later JSON encoded and stored in the
configuration
field of theCondition
model. But that part isn't important to this bug report so has been removed from the example.Perhaps there's some other way to achieve what I need?
Expected behavior
No JS errors. State data returned in request upon save.
Steps to reproduce
Available in the example Git repo: https://github.com/Muffinman/filament-repeater-bug/blob/master/app/Filament/Resources/DiscountResource.php
Repeater
referencing a relationship. In my case I have aDiscount
model referencing one or moreConditions
.Repeater
Customer ID
condition, we need to provide the customer.\Closure
toFieldset::schema()
to dynamically render different fields depending on theDiscount
typeReproduction repository
https://github.com/Muffinman/filament-repeater-bug
Relevant log output