F
Filament2mo ago
lbar

modal form passing value from the action

In my view I have the following action:
{{ ($this->subscribeMemberAction)(['member_id' => $member->id]) }}
{{ ($this->subscribeMemberAction)(['member_id' => $member->id]) }}
this work pretty well, and I'm able to fetch my data from fillForm on the component:
return Action::make('subscribeMember')
->fillForm(function (array $arguments){
return Member::where('id', '=', $arguments['member_id'])->first()->toArray();
)
[...]
return Action::make('subscribeMember')
->fillForm(function (array $arguments){
return Member::where('id', '=', $arguments['member_id'])->first()->toArray();
)
[...]
but I need to pre-fetch some options (extracting them from database) using the same $arguments['member_id']. So something like this, but here the $arguments is not available
[...]
->schema([
Radio::make('member_certificates')
->options(function ($arguments){
// here $arguments['member_id'] is not available
return MemberCertificate::where('member_id', '=', $arguments['member_id'])->pluck('id','expire_Date')->toArray();
})
])
[...]
[...]
->schema([
Radio::make('member_certificates')
->options(function ($arguments){
// here $arguments['member_id'] is not available
return MemberCertificate::where('member_id', '=', $arguments['member_id'])->pluck('id','expire_Date')->toArray();
})
])
[...]
Any clue on how to archive that? Thank you
Solution:
try only this ```php return Actions\Action::make('subscribeMember') ->mountUsing(function (Form $form, array $arguments) {...
Jump to solution
12 Replies
LeandroFerreira
LeandroFerreira2mo ago
try
Actions\Action::make('subscribeMember')
->mountUsing(function (Form $form, array $arguments) {
$form->getComponent($form->getStatePath().'.member_certificates')
->options(fn () => MemberCertificate::whereMemberId($arguments['member_id'])
->pluck('id', 'expire_Date')
);
})
->form([
Radio::make('member_certificates'),
])
->action(function () {...})
Actions\Action::make('subscribeMember')
->mountUsing(function (Form $form, array $arguments) {
$form->getComponent($form->getStatePath().'.member_certificates')
->options(fn () => MemberCertificate::whereMemberId($arguments['member_id'])
->pluck('id', 'expire_Date')
);
})
->form([
Radio::make('member_certificates'),
])
->action(function () {...})
lbar
lbarOP2mo ago
removed my previous answer because obviously wrong, by the way at that time, also with your example i'm not able to populate my radio on modal start...still trying... probably found. The form that i'm using is a step (wizard), so my guess is that $form->getStatePath().'.member_certificates' isn't getting correctly my field
LeandroFerreira
LeandroFerreira2mo ago
share the whole code on gist
lbar
lbarOP2mo ago
https://gist.github.com/barianiluca/22849db816cd0a65c65064c200b35dc5 thank you for now workarounded saving the member_id on the session, but not quite sure that is the best approach. imho the step/wizard form require a different mountUsing, but didn't find something on the docs
LeandroFerreira
LeandroFerreira2mo ago
where are you using this action?
lbar
lbarOP2mo ago
livewire component, called like: {{ ($this->subscribeMemberAction)(['member_id' => $member->id]) }}
LeandroFerreira
LeandroFerreira2mo ago
->mountUsing(function (Form $form, array $arguments) {
dd($arguments);
->mountUsing(function (Form $form, array $arguments) {
dd($arguments);
Does dd show the member_id? Did you try static values like
->mountUsing(function (Form $form, array $arguments) {
$form->getComponent($form->getStatePath() . '.member_certificates')
->options([
'1' => 'Certificate 1',
'2' => 'Certificate 2',
]);
})
->mountUsing(function (Form $form, array $arguments) {
$form->getComponent($form->getStatePath() . '.member_certificates')
->options([
'1' => 'Certificate 1',
'2' => 'Certificate 2',
]);
})
Does it work? hide other steps and try only Documents
lbar
lbarOP2mo ago
yep, the dd($arguments) works, but I need to comment the fillForm followed (but this is fine, i found this also in the doc). The static options doesn't work too. But this morning i have tried to comment everything from my stepper form, and create an example with the simple form like your own example, and it worked. It's for that, that my guess are that this $form->getComponent($form->getStatePath() . '.member_certificates') can't grab the correct input on the Documents step yes also trying to comment everything, aside Documents didn't works
Solution
LeandroFerreira
LeandroFerreira2mo ago
try only this
return Actions\Action::make('subscribeMember')
->mountUsing(function (Form $form, array $arguments) {
$form->getComponent($form->getStatePath() . '.member_certificates')
->options(fn() => MemberCertificate::whereMemberId($arguments['member_id'])
->pluck('id', 'expire_Date')
);
})
->steps([
Step::make('Documents')
->schema([
Radio::make('member_certificates')
]),
]);
return Actions\Action::make('subscribeMember')
->mountUsing(function (Form $form, array $arguments) {
$form->getComponent($form->getStatePath() . '.member_certificates')
->options(fn() => MemberCertificate::whereMemberId($arguments['member_id'])
->pluck('id', 'expire_Date')
);
})
->steps([
Step::make('Documents')
->schema([
Radio::make('member_certificates')
]),
]);
lbar
lbarOP2mo ago
uh, this worked :squint:
LeandroFerreira
LeandroFerreira2mo ago
I think you can add step by step and see where is the issue... But I think you can achieve what you want using mountUsing as I mentioned
lbar
lbarOP2mo ago
ok i'll try in my way, thank you very muck for your extensive support on this. much appreciate

Did you find this page helpful?