Default Key-Value when creating a new record
While we can set a default value for a normal input field, I can't seem to find the option to do the same for a key-value field.
Is it possible to set a default array value on page load?
5 Replies
What have you tried? Please share the code.
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:
The second thing I have tried was use the default method on the KeyValue field:
`
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.
KeyValue isn’t designed to work with arrays like this.
Solution
this should be
Yea that works, cheers.