Deferred loading with form in laravel component

I have a slideover in a livewire component where I'm using deferred loading, so that the model isn't set until the user clicks on an element to open it. So I've got this:
public function render()
{
return view('livewire.components.queues.document-edit-modal', [
'data' => $this->isOpen ? $this->getData() : []
]);
}
public function render()
{
return view('livewire.components.queues.document-edit-modal', [
'data' => $this->isOpen ? $this->getData() : []
]);
}
Where $this->getData() gets the data and then calls $this->form->fill($this-model->toArray()). That all works fine, however, I also want to use live fields on the form so that when the user changes one field, the model is updated without them having to click submit, so I'm using the live() method on the form fields. But when you change a field, the form immediately re-renders because of $this->form->fill() presumably. I'm sure I'm just not thinking about something correctly, because I feel like this should be pretty straight forward. Here's my form:
return $form->schema([
TextInput::make('reference_number')
->label('Reference Number')
->live(debounce: 500)
->afterStateUpdated(function (?string $state, ?string $old) {
$this->item->reference_number = $state;
$this->item->save();
}),

])->statePath('data')
->model($this->item)
->disabled(fn () => !empty($this->item->details_confirmed_at));
}
return $form->schema([
TextInput::make('reference_number')
->label('Reference Number')
->live(debounce: 500)
->afterStateUpdated(function (?string $state, ?string $old) {
$this->item->reference_number = $state;
$this->item->save();
}),

])->statePath('data')
->model($this->item)
->disabled(fn () => !empty($this->item->details_confirmed_at));
}
What am I doing wrong here?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server