F
Filamentβ€’13mo ago
ericmp

How to retrieve form's data inside requiresConfirmation fn?

Action::make('New song')
->form([
TextInput::make('name')
->required()
->maxLength(255)
,
...
])
->action(function (array $data): void {
$song = Song::create([
'name' => str($data['name'])->trim()->lower()->title(),
...
]);
})
->requiresConfirmation(function (array $data) {
dd($data); // how to get the name??? i always get an empty array
})
Action::make('New song')
->form([
TextInput::make('name')
->required()
->maxLength(255)
,
...
])
->action(function (array $data): void {
$song = Song::create([
'name' => str($data['name'])->trim()->lower()->title(),
...
]);
})
->requiresConfirmation(function (array $data) {
dd($data); // how to get the name??? i always get an empty array
})
9 Replies
ericmp
ericmpOPβ€’13mo ago
the objective is to show an alert confirmation to the user if the name contains a specific string
mariusticha
mariustichaβ€’13mo ago
i think the closure you can pass into requiresConfirmation() is there to evaluate if the action needs confirmation or not. it's not meant to evaluate the action's form data if you leave the parameter of requiresConfirmation() blank you can see that it triggers a confirmation modal rendering the form so imo it is not intended to retrieve the action's form input and require an additional confirmation for this input
Dennis Koch
Dennis Kochβ€’13mo ago
I am not sure you can use ->form() and ->requiresConfirmation() at the same time.
mariusticha
mariustichaβ€’12mo ago
it seems that you can do so, but the result is a requires confirmation modal containing the form when you confirm the modal, the result of the form is available in the ->action() method. but there is no additional confirmation required based on the form input
Dennis Koch
Dennis Kochβ€’12mo ago
Yes, that's what I mean. They are using the same modal.
mariusticha
mariustichaβ€’12mo ago
maybe form validation or notifications can be a help in this use case
ericmp
ericmpOPβ€’12mo ago
oh, so is not possible to achieve? :/ hmmm yeah but is not actually a validation, cuz technically there is no errors, but only an alert to let the user know that a song is named like that aswell and using notifications πŸ€” ... well when the notification will be shown? i think i when i get inside the action, check if the name already exists and popup a notification? but i think will be like z-indexed under the modal (not sure yet, have to test it out), but yeah ill find a workaround
Dennis Koch
Dennis Kochβ€’12mo ago
cuz technically there is no errors, but only an alert to let the user know that a song is named like that aswell
That sounds exactly like a unique validation πŸ˜…
ericmp
ericmpOPβ€’12mo ago
but i mean, its ok that there is 2 songs with the same name, maybe they are from diferent artists i just want to let the user know that there is already a song with that name
Want results from more Discord servers?
Add your server