mountFormComponentAction no longer works after upgrade to v4
I have the following code for filament v3. It's opening a modal when the type is 'hour'.
Unfurtunatly this is no longer working after upgrade te v=filament v4. Can someone please help me?
protected static function getArticleSelectionField(): Select
{
return Select::make('article_id')
->label('Article')
->relationship('article', 'name')
->live()
->afterStateUpdated(function (Get $get, Set $set, $state, $livewire, $component) {
$set('quantity', $article->unit === 'hour' ? 0 : 1);
// Auto-open the modal if unit is hour
if ($article->unit === 'hour') {
$livewire->mountFormComponentAction(
$component->getStatePath(),
'show_time_modal'
);
}
})
->registerActions([
Action::make('show_time_modal')
->label('Calculate T')
->modalHeading('Work C')
->form([
TimePicker::make('from_time')->required()->seconds(false),
TimePicker::make('to_time')->required()->seconds(false),
])
->action(function (array $data, Get $get, Set $set) {
$from = \Carbon\Carbon::parse($data['from_time']);
$to = \Carbon\Carbon::parse($data['to_time']);
.....
})
->mountUsing(function ($form) {
$form->fill([
'from_time' => now()->format('H:i'),
'to_time' => now()->addHour()->format('H:i'),
]);
})
->modalSubmitActionLabel('Apply')
->modalCancelActionLabel('Cancel'),
]);
}
5 Replies
Thanks, I did see this post already.
And I tried it, but I did not see the modal popping up. Or I am doing something wrong or there is something else.
Please share the whole code that you are using on gist or github
There is not much code. These are my two files.
One is the resource, the other one is a trait. The code above is from the trait.
It works as I expect. When the chosen articles unit type is 'hour', a modal opens up to fill the hours in filament v3.
Sorry for not beeing able to give more info