Relationship Repeater in EditRecord saves before beforeSave?

What I am trying to do: Create a group of changes when someone creates or updates records in Filament. Some of the elements are repeaters with relationships. What I did: I'm able to do this properly in the CreateRecord because all of the creating happens between beforeCreate and afterCreate. However, in the EditRecord I tried to use the beforeSave and afterSave, but the relationship repeater ends up being saved within the $data = $this->form->getState()
$this->callHook('beforeValidate');

$data = $this->form->getState();

$this->callHook('afterValidate');
$this->callHook('beforeValidate');

$data = $this->form->getState();

$this->callHook('afterValidate');
My issue/the error: I tried to get around the issue by adding my grouping code into the beforeValidate, but then I end up with empty groups when the validation fails. My question: Is there some other event that I haven't found yet that I can listen within the EditRecord page that will trigger after all the validation, and before any relationship repeaters are saved? My initial expectation was that the EditRecord would perform all of it's saving between beforeSave and afterSave, but it doesn't appear that's the case.
2 Replies
BasketMC
BasketMCOP11mo ago
Interesting idea… I’ll give that a try, thanks! Ok, I found a workaround, in the ->beforeValidate() method, if I manually call the $this->form->validate() method then I can ensure that the validation will pass. It feels a little awkward, but fine for now 🙂
protected function beforeValidate(): void
{
$this->form->validate();
//My grouping code
}
protected function beforeValidate(): void
{
$this->form->validate();
//My grouping code
}
Want results from more Discord servers?
Add your server