fix: Select label update when not preloaded

This commit is contained in:
Dan Harrin
2024-03-14 10:26:22 +00:00
parent af9a4c08b1
commit 41134b5b78
3 changed files with 16 additions and 8 deletions
File diff suppressed because one or more lines are too long
@@ -146,7 +146,7 @@ export default function selectFormComponent({
}
await this.refreshChoices({
withInitialOptions: !hasDynamicOptions,
withInitialOptions: false,
})
},
)
+14 -6
View File
@@ -433,10 +433,8 @@ class Select extends Field implements Contracts\CanDisableOptions, Contracts\Has
})
->fillForm($this->getEditOptionActionFormData())
->action(static function (Action $action, array $arguments, Select $component, array $data, ComponentContainer $form) {
$statePath = $component->getStatePath();
if (! $component->getUpdateOptionUsing()) {
throw new Exception("Select field [{$statePath}] must have a [updateOptionUsing()] closure set.");
throw new Exception("Select field [{$component->getStatePath()}] must have a [updateOptionUsing()] closure set.");
}
$component->evaluate($component->getUpdateOptionUsing(), [
@@ -444,9 +442,7 @@ class Select extends Field implements Contracts\CanDisableOptions, Contracts\Has
'form' => $form,
]);
/** @var LivewireComponent $livewire */
$livewire = $component->getLivewire();
$livewire->dispatch('filament-forms::select.refreshSelectedOptionLabel', livewireId: $livewire->getId(), statePath: $statePath);
$component->refreshSelectedOptionLabel();
})
->color('gray')
->icon(FilamentIcon::resolve('forms::components.select.actions.edit-option') ?? 'heroicon-m-pencil-square')
@@ -1226,4 +1222,16 @@ class Select extends Field implements Contracts\CanDisableOptions, Contracts\Has
return $relationship->getQualifiedOwnerKeyName();
}
public function refreshSelectedOptionLabel(): void
{
/** @var LivewireComponent $livewire */
$livewire = $this->getLivewire();
$livewire->dispatch(
'filament-forms::select.refreshSelectedOptionLabel',
livewireId: $livewire->getId(),
statePath: $this->getStatePath(),
);
}
}