F
Filament2mo ago
Zyten

Using disabledOn('edit') with fieldsets seems to make the fields empty on save

I did the same for a bunch of standard fields (Select, TextInput etc) and they work as expected. My goal is to make everything except two TextInput readonly when on the Edit form. Would also be happy to know if there are other ways to achieve this besides disabledOn('edit'). Thank you
Forms\Components\Fieldset::make('income')
->label('Income')
->schema([
Forms\Components\Select::make('income.bracket')
->required()
->disabledOn('edit')
->placeholder('Select')
->native(false)
->options(IncomeBracketEnum::class)
->selectablePlaceholder(false)
->reactive(),
Forms\Components\TextInput::make('income.amount')
->required()
->disabledOn('edit')
->numeric()
->minValue(0)
->default(0)
->reactive(),
])
Forms\Components\Fieldset::make('income')
->label('Income')
->schema([
Forms\Components\Select::make('income.bracket')
->required()
->disabledOn('edit')
->placeholder('Select')
->native(false)
->options(IncomeBracketEnum::class)
->selectablePlaceholder(false)
->reactive(),
Forms\Components\TextInput::make('income.amount')
->required()
->disabledOn('edit')
->numeric()
->minValue(0)
->default(0)
->reactive(),
])
5 Replies
Zyten
Zyten2mo ago
Was kinda able to bypass the issue by having this in the Edit class:
protected function handleRecordUpdate(Model $record, array $data): Model
{
if (empty($data['income']))
$data['income'] = $record->income;

$record->update($data);

return $record;
}
protected function handleRecordUpdate(Model $record, array $data): Model
{
if (empty($data['income']))
$data['income'] = $record->income;

$record->update($data);

return $record;
}
Unsure if this is the proper way to deal with this tho
toeknee
toeknee2mo ago
I have a feeling you are not casting your income repeater to an array within the model hence why it's looking empty possibly.
Zyten
Zyten2mo ago
Hi, I cast it like so actually:
protected function casts(): array
{
return [
'income' => 'array',
];
}
protected function casts(): array
{
return [
'income' => 'array',
];
}
And just to be clear when I said its empty, I see $data['income'] == []
toeknee
toeknee2mo ago
Is this in a custom livewire component?
Zyten
Zyten2mo ago
Nope. Standard Resource Form altho the form itself is quite nested
return $form
->schema([
Grid::make()
->schema([
Group::make([//fieldset here])
])
return $form
->schema([
Grid::make()
->schema([
Group::make([//fieldset here])
])
Want results from more Discord servers?
Add your server