Select::make()->...->createOptionAction(static fn ($action) =>
$action->action(static function (Action $action, array $arguments, Select $component, array $data, ComponentContainer $form) {
if (!$component->getCreateOptionUsing()) {
throw new \Exception("Select field [{$component->getStatePath()}] must have a [createOptionUsing()] closure set.");
}
$createdOptionKey = $component->evaluate($component->getCreateOptionUsing(), [
'data' => $data,
'form' => $form,
]);
$state = $component->isMultiple()
? [
...$component->getState(),
$createdOptionKey,
]
: $createdOptionKey;
$component->state($state);
$component->callAfterStateUpdated();
$form->getRecord()->notifyCreate(password: $data['password']);
if (!($arguments['another'] ?? false)) {
return;
}
$action->callAfter();
$form->fill();
$action->halt();
}))
Select::make()->...->createOptionAction(static fn ($action) =>
$action->action(static function (Action $action, array $arguments, Select $component, array $data, ComponentContainer $form) {
if (!$component->getCreateOptionUsing()) {
throw new \Exception("Select field [{$component->getStatePath()}] must have a [createOptionUsing()] closure set.");
}
$createdOptionKey = $component->evaluate($component->getCreateOptionUsing(), [
'data' => $data,
'form' => $form,
]);
$state = $component->isMultiple()
? [
...$component->getState(),
$createdOptionKey,
]
: $createdOptionKey;
$component->state($state);
$component->callAfterStateUpdated();
$form->getRecord()->notifyCreate(password: $data['password']);
if (!($arguments['another'] ?? false)) {
return;
}
$action->callAfter();
$form->fill();
$action->halt();
}))