Sven
Sven
FFilament
Created by Sven on 11/6/2023 in #❓┊help
Default Key-Value when creating a new record
Yea that works, cheers.
8 replies
FFilament
Created by Sven on 11/6/2023 in #❓┊help
Default Key-Value when creating a new record
The first thing I have tried was hook into the afterStateUpdated method of a TextInput field and set the value of the KeyValue with an empty array:
Forms\Components\TextInput::make('name')
->label('Naam')
->required()
->live(onBlur: true)
->afterStateUpdated(function (string $operation, $state, Forms\Set $set) {
if ($operation !== 'create') {
return;
}
$set('meta', ['sizes' => [],'colors' => [], 'types' => []]);
}),
Forms\Components\TextInput::make('name')
->label('Naam')
->required()
->live(onBlur: true)
->afterStateUpdated(function (string $operation, $state, Forms\Set $set) {
if ($operation !== 'create') {
return;
}
$set('meta', ['sizes' => [],'colors' => [], 'types' => []]);
}),
The second thing I have tried was use the default method on the KeyValue field:
Forms\Components\KeyValue::make('meta')
->label('Eigenschappen')
->keyLabel('Variatie')
->columnSpan('full')
->keyPlaceholder('Property name')
->reorderable()
->default([
'sizes' => ['S', 'M', 'L', 'XL', 'XXL'],
'colors' => [],
'types' => ['VERPAKT','GEVOUWEN','STICKERS'],
]),
Forms\Components\KeyValue::make('meta')
->label('Eigenschappen')
->keyLabel('Variatie')
->columnSpan('full')
->keyPlaceholder('Property name')
->reorderable()
->default([
'sizes' => ['S', 'M', 'L', 'XL', 'XXL'],
'colors' => [],
'types' => ['VERPAKT','GEVOUWEN','STICKERS'],
]),
` While the the above default values get shown inside of the KeyValue field, I am getting the following error when submitting the resource form: Filament\Forms\Components\KeyValue::Filament\Forms\Components{closure}(): Argument #1 ($value) must be of type ?string, array given However, when I manually add the above values, the form submits succesfully and the values get saved as an array inside of my database.
8 replies