Action inside Another Action

I have action inside action for modal payment operation it contain form inside every action but not able to validate any thing it just taking me to the next step without validation is there a way to prevent that and do a validation in each step
Action::make('first')
->requiresConfirmation()
->action(function () {
// ...
})
->extraModalFooterActions([
Action::make('second')
->requiresConfirmation()
->action(function () {
// ...
})
->extraModalFooterActions([
Action::make('third')
->requiresConfirmation()
->action(function () {
// ...
})
->extraModalFooterActions([
Action::make('fourth')
->requiresConfirmation()
->action(function () {
// ...
})
->cancelParentActions('second'),
]),
]),
])
Action::make('first')
->requiresConfirmation()
->action(function () {
// ...
})
->extraModalFooterActions([
Action::make('second')
->requiresConfirmation()
->action(function () {
// ...
})
->extraModalFooterActions([
Action::make('third')
->requiresConfirmation()
->action(function () {
// ...
})
->extraModalFooterActions([
Action::make('fourth')
->requiresConfirmation()
->action(function () {
// ...
})
->cancelParentActions('second'),
]),
]),
])
11 Replies
Sourabh
Sourabh10mo ago
you can prevent action like this
<?php ->action(function (Actions\Action $action, array $data) {

if(empty($data)){

$action->cancel();
}

your logic here....

})
<?php ->action(function (Actions\Action $action, array $data) {

if(empty($data)){

$action->cancel();
}

your logic here....

})
GHOST-117
GHOST-117OP10mo ago
will it validate the fields
Sujal Tamrakar
Sujal Tamrakar10mo ago
You could also use steps instead of forms which will provide you with a wizard
GHOST-117
GHOST-117OP10mo ago
i a single modal i have take payment and a option to send invoice button in wizard i cant jump steps directly
gladjanus43
gladjanus4310mo ago
you have the ->skippable() method for the wizard? Dont know if that is what you mean though...
GHOST-117
GHOST-117OP10mo ago
nope EX- i have a modal and have 2 button 1 is for take payment and 2nd one is for Send invoice for them i have separate functionality so skippable will just skip the next step so it wont work and i have tried to implement that ......but not working for my case
KeyMe
KeyMe10mo ago
why not just make separate action/modal? for both
gladjanus43
gladjanus4310mo ago
would this then be the solution? to check if the first action is valid or can be executed, if so just continue the process and otherwise halt it
GHOST-117
GHOST-117OP10mo ago
Like this
->modalFooterActions([

Action::make('TakePayment')
->extraAttributes(['class' => 'take-payment-btn'])

->submit('TakePayment')
->action(function(){
$this->halt();
})
->modalFooterActions([

Action::make('TakePayment')
->extraAttributes(['class' => 'take-payment-btn'])

->submit('TakePayment')
->action(function(){
$this->halt();
})
gladjanus43
gladjanus4310mo ago
Im sorry, I dont really understand what you are trying to achieve... Are you opening model after model based on the prvious action? If so im not sure it is the best way to go but would the first action maybe look like this:
Action::make('first')
->requiresConfirmation()
->action(function ($action) {
if(!somevalidation){
$action->halt();
}
... rest of your code
}
})
Action::make('first')
->requiresConfirmation()
->action(function ($action) {
if(!somevalidation){
$action->halt();
}
... rest of your code
}
})
GHOST-117
GHOST-117OP10mo ago
yes iam iam opeaning the modal based on privious action i have chain of modalFooterActions action inside action and forms
Want results from more Discord servers?
Add your server