F
Filamentβ€’8mo 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
ericmpβ€’8mo ago
the objective is to show an alert confirmation to the user if the name contains a specific string
mariusticha
mariustichaβ€’8mo 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β€’8mo ago
I am not sure you can use ->form() and ->requiresConfirmation() at the same time.
mariusticha
mariustichaβ€’8mo 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β€’8mo ago
Yes, that's what I mean. They are using the same modal.
mariusticha
mariustichaβ€’8mo ago
maybe form validation or notifications can be a help in this use case
ericmp
ericmpβ€’8mo 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β€’8mo 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
ericmpβ€’8mo 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
More Posts