Select with Multiple and Required Not Working with Dynamically Generated Schema

Hello - has anyone had any difficulty using select, multiple, and required in the same element? For example:
->schema(function (callable $get) {
$schema = [];

// ...

foreach($mealModifierCategories as $i => $category) {
$schema[] = Select::make('modifierCategory.' . $category->id)
->label($category->name)
->required($category->required)
->multiple($category->limit == null || $category->limit > 1)
->hint(function () use ($category) {
if($category->required) {
if($category->limit == null) {
return 'Required';
} else {
return 'Required - Limit: ' . $category->limit;
}
} else {
if($category->limit == null) {
return null;
} else {
return 'Optional - Limit: ' . $category->limit;
}
}
})
->hintColor('primary')
->options(MealModifierOption::where([
['meal_modifier_category_id', $category->id],
['meal_id', $meal]
])->pluck('name', 'id')->toArray());
}
return $schema;
})
->schema(function (callable $get) {
$schema = [];

// ...

foreach($mealModifierCategories as $i => $category) {
$schema[] = Select::make('modifierCategory.' . $category->id)
->label($category->name)
->required($category->required)
->multiple($category->limit == null || $category->limit > 1)
->hint(function () use ($category) {
if($category->required) {
if($category->limit == null) {
return 'Required';
} else {
return 'Required - Limit: ' . $category->limit;
}
} else {
if($category->limit == null) {
return null;
} else {
return 'Optional - Limit: ' . $category->limit;
}
}
})
->hintColor('primary')
->options(MealModifierOption::where([
['meal_modifier_category_id', $category->id],
['meal_id', $meal]
])->pluck('name', 'id')->toArray());
}
return $schema;
})
I have only had an issue when I am dynamically generating the schema. When I submit the form, I get an error saying I must make a selection even though I already have (screenshot attached). Strangely, this error does not occur when the user is only allowed to select one option (i.e.: ->multiple(false)).
10 Replies
LeandroFerreira
LeandroFerreira17mo ago
It was supposed to work.. is the $category->id unique?
bwurtz999
bwurtz999OP17mo ago
Yes it is unique I have used this type of select component in the past without issue. The only real difference I can think of is that this schema is dynamically generated Could that be the cause?
LeandroFerreira
LeandroFerreira17mo ago
can you share the project on github?
bwurtz999
bwurtz999OP17mo ago
The entire project?
LeandroFerreira
LeandroFerreira17mo ago
or a fresh install with this resource
bwurtz999
bwurtz999OP17mo ago
It's actually a custom form in a relation manager that is triggered from protected function getTableHeaderActions() So after some more trial and error, I've realized that it isn't specifically related to the ->multiple() option I dynamically create these attributes, and I get the following console error when they appear
bwurtz999
bwurtz999OP17mo ago
bwurtz999
bwurtz999OP17mo ago
When I get this error, all of these fields end up as NULL after I submit the form
bwurtz999
bwurtz999OP17mo ago
I believe my issue is related to a broader Filament issue: https://github.com/filamentphp/filament/discussions/4350
GitHub
Dynamic reactive fields · filamentphp filament · Discussion #4350
Hi, I'm wondering if it's currently possible to produce dynamic forms with different fields depending on what was selected earlier in the form. We sort of have this working, but it uses Com...
bwurtz999
bwurtz999OP17mo ago
related to dynamically created form fields In case this helps anyone else in the future, I had to work around this by generating the form fields on the initial page load and then using visible() to show/hide them
Want results from more Discord servers?
Add your server