Clear hidden field on toggle off

The toggle is working well with the field been hidden and shown but the hidden field is not cleared.
No description
3 Replies
Hugo
Hugo15mo ago
Can you make a video of the problem ?
cheesegrits
cheesegrits15mo ago
What do you mean by "the hidden ffield is not cleared"? Do you mean if you edit a record which has 'trustHolder' set, and a value for 'trustee', then you unselect trustHolder, trustee gets hidden, and you save the record? And trustee still has it's old value? I would expect that to be the case, because hidden fields are not updated when you save. So the field on that row will remain unchanged. You'll probably need to either keep it visible, or manually add it to the data when saving, either with a mutateFormDataBeforeSave() method, or in your own save method (depending whether you are in a panel or standalone context). So if you are in an admin panel, try this on your EditFoo page ...
protected function mutateFormDataBeforeSave(array $data): array
{
if (! $data['trustHolder']) {
$data['trustee'] = null;
}

return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{
if (! $data['trustHolder']) {
$data['trustee'] = null;
}

return $data;
}
eliud.kinyanjui
eliud.kinyanjuiOP15mo ago
Thanks, that was the issue. The value was still being saved after you turn off the toggle.
Want results from more Discord servers?
Add your server