I solved it by putting the listeners in the ListRecord, EditRecord, and CreateRecord pages, not the relative Resource page. To refresh the edit form after updating, for example, you would use refreshFormData() and pass it the field names you want to refresh. For example, $this->refreshFormData(['created_at', 'updated_at']);. Normally you probably wouldn't need to do this, but I did because I auto-set some date fields based on the $status that was submitted.
Here's an updated example:
class EditUser extends EditRecord
{
protected static string $resource = UserResource::class;
#[On('user-updated')]
public function userFormUpdated(): void
{
$this->refreshFormData(['terminated_at', 'joined_at', 'approved_at']);
}
public function afterSave(): void
{
// Run update of status to make sure dates are proper
$this->record->processUser(status: $this->record->status);
// This should trigger event to refresh user form
$this->dispatch('user-updated');
}
}
Also, using an event listeners array didn't appear to work, so use the #[On('eventName')] format. Don't forget to import the On class!
Didn't work:
protected $listeners = ['user-updated' => 'userFormUpdated'];
Did work:
#[On('user-updated')]
public function userFormUpdated(): void
{