F
Filament14mo ago
Chriis

How to retrieve an array mutated before save in the edit form of a record ?

Hi, I have two separate fields in my form and before save I mutate them into an array (JSON into the database). However, when I edit a record, the data in this array are not retrieve. Possibly because in the Livewire object I have the array I define in the mutation before saving, with data, but also the two field in root of the object which are null. So how can I use the data in this mutate array when I retrieve the record and how to delete the two, now useless, keys ? The two fields :
return Fieldset::make('Durée')
->schema([
TextInput::make('hours')
->label('Heure(s)')
->suffix('h')
->numeric()
->required(),
TextInput::make('days')
->label('Jour(s)')
->suffix('j')
->numeric()
->live()
->afterStateUpdated(function (Forms\Set $set, $state){
$set('days_hidden', $state);
})
->required()
]);
return Fieldset::make('Durée')
->schema([
TextInput::make('hours')
->label('Heure(s)')
->suffix('h')
->numeric()
->required(),
TextInput::make('days')
->label('Jour(s)')
->suffix('j')
->numeric()
->live()
->afterStateUpdated(function (Forms\Set $set, $state){
$set('days_hidden', $state);
})
->required()
]);
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['duration'] = [
'hours' => (int) $data['hours'],
'days' => (int) $data['days']
];

return $data;
}
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['duration'] = [
'hours' => (int) $data['hours'],
'days' => (int) $data['days']
];

return $data;
}
No description
3 Replies
Chriis
ChriisOP14mo ago
Problem partially solved with mutateFormDataBeforeFill(). The edit form now have all the values in the fields, BUT in the livewire object they are still duplicated. I think its not really important but it would be better if I could delete them.
Chriis
ChriisOP14mo ago
At the start of the object :
No description
Chriis
ChriisOP14mo ago
Further down in the object :
No description
Want results from more Discord servers?
Add your server