Toggle saving to DB but not initializing with correct value

I have a form with a Toggle input on it. It's updating the database when I save the form, but when the page refreshes it's not showing the correct value. It's always "on". This is on a Page class. I have this in my mount method:
$this->form->fill([
'field_id' => $this->detail->field_id,
]);
$this->form->fill([
'field_id' => $this->detail->field_id,
]);
and here's my form:
public function form(Form $form): Form
{
return $form
->schema([
Section::make('Section')
->description('Configure the sales tax details for the client.')
->schema([
Toggle::make('field_id')->label('Field Label')->columnStart(1),
])->aside()
->footerActions([
Action::make('save')
->label('Save')
->action(function (?Model $record, Component $component) {
$record->update($component->getState());

Notification::make()
->title('Updated successfully')
->success()
->send();
})
])->footerActionsAlignment(Alignment::End)
->columns(2)
])
->statePath('data')
->model($this->detail);
}
public function form(Form $form): Form
{
return $form
->schema([
Section::make('Section')
->description('Configure the sales tax details for the client.')
->schema([
Toggle::make('field_id')->label('Field Label')->columnStart(1),
])->aside()
->footerActions([
Action::make('save')
->label('Save')
->action(function (?Model $record, Component $component) {
$record->update($component->getState());

Notification::make()
->title('Updated successfully')
->success()
->send();
})
])->footerActionsAlignment(Alignment::End)
->columns(2)
])
->statePath('data')
->model($this->detail);
}
Any ideas?
1 Reply
Jon Mason
Jon MasonOP9mo ago
nvm...I had an attribute that was modifying the value and I didn't realize it..
Want results from more Discord servers?
Add your server