KeyValue UI not updating after $set(), but the value is changed

Hi Guys, I am using a button to change the keys and/or values in a KeyValue field that already contains data. When i do this the UI does not change, but the value will.
return $form
->schema([
...
Forms\Components\KeyValue::make('meta'),
...
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('button')
->action(function (Set $set) {
$set('meta.a', 'foo');
$set('meta.b', 'bar');
$set('meta.c', 'baz');
}),
...
return $form
->schema([
...
Forms\Components\KeyValue::make('meta'),
...
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('button')
->action(function (Set $set) {
$set('meta.a', 'foo');
$set('meta.b', 'bar');
$set('meta.c', 'baz');
}),
...
The weird thing is that it works when the meta field is either NULL or an empty array, OR when i manually make a change to the KeyValue field first. Am i doing something wrong or is this a bug? Thanks in advance! demo repo: https://github.com/rickzim/demo-filament-key-value
GitHub
GitHub - rickzim/demo-filament-key-value
Contribute to rickzim/demo-filament-key-value development by creating an account on GitHub.
No description
4 Replies
tuto1902
tuto19027mo ago
Try using $this->refreshFormData('meta') in the action code. This should refresh the form data for the meta attribute https://filamentphp.com/docs/3.x/panels/pages#refreshing-form-data
Corvack
Corvack7mo ago
This sadly does not work. I think you would normally use this when you want to refresh the main form to reflect changes you made from, for example a header action.
tuto1902
tuto19027mo ago
how about adding ->live() to the KeyValue form field
Forms\Components\KeyValue::make('meta')
->live(),
Forms\Components\KeyValue::make('meta')
->live(),
Corvack
Corvack7mo ago
I tried many different combinations but i couldn't get it to work.