Validate multiple dynamic fields
hey there. I need to validate muliple dynamic fields in a special way. if you look at the screenshot you see some checkboxes. for each checked checkbox a new field apears. all fields together, summed up, must be 100. how can I validate this?
this is how I generatet the fields:
Forms\Components\CheckboxList::make('materials')
->label(false)
->gridDirection('row')
->columns(2)
->bulkToggleable()
->required()
->live()
->relationship('materials', 'name', modifyQueryUsing: fn (Builder $query) => $query->orderBy('id')),
Forms\Components\Fieldset::make(__('backend.materials.fields.plural_share'))
->visible(function(Forms\Get $get) {
return $get('materials');
})
->schema(function(Forms\Get $get) {
$fields = [];
if($get('materials')) {
$materials = Material::whereIn('id',$get('materials'))->pluck('name','id')->toArray();
foreach($get('materials') as $material) {
$fields[] = TextInput::make('material_'.$material)
->label($materials[$material])
->required()
->suffix('%')
->numeric()
->minValue(1)
->maxValue(100);
}
}
return $fields;
}),
Solution:Jump to solution
Hi there... you could use something like this?
```PHP
Forms\Components\CheckboxList::make('materials')
->label(false)...
4 Replies