F
Filament2w ago
Xavi

Alert before create button on list

Is it possible to show and alert before create modal its show?. I want to alert user that he has made X questions before create it. This is my header actions code:
protected function getHeaderActions(): array
{
return [
CreateAction::make()
->label(__('Nueva pregunta'))
->visible(fn(): bool => Carbon::parse($this->record->allow_questions_from)->startOfDay()->lte(Carbon::now()->startOfDay()) &&
Carbon::parse($this->record->allow_questions_to)->endOfDay()->gte(Carbon::now()->endOfDay())
)
->form([
Select::make('teacher_id')
->label(__('Teacher'))
->options($this->record->users->pluck('name', 'id')->toArray())
->placeholder(__('Selecciona un docente'))
->visible($this->record->users->count() > 1)
->required(),
TextInput::make('subject')
->label(__('Temática'))
->required(),
Textarea::make('content')
->label(__('Escribe tu pregunta'))
->rows(10)
->required(),
])
->action(
function (array $data) {
$question = CreateQuestionAction::run($data + ['module_id' => $this->record->id]);

$this->dispatch('open-modal', id: 'thank-you-modal', parameters: [
'question' => $question,
]);
})
->createAnother(false)
->modalHeading('')
->icon('heroicon-o-plus')
];
}
protected function getHeaderActions(): array
{
return [
CreateAction::make()
->label(__('Nueva pregunta'))
->visible(fn(): bool => Carbon::parse($this->record->allow_questions_from)->startOfDay()->lte(Carbon::now()->startOfDay()) &&
Carbon::parse($this->record->allow_questions_to)->endOfDay()->gte(Carbon::now()->endOfDay())
)
->form([
Select::make('teacher_id')
->label(__('Teacher'))
->options($this->record->users->pluck('name', 'id')->toArray())
->placeholder(__('Selecciona un docente'))
->visible($this->record->users->count() > 1)
->required(),
TextInput::make('subject')
->label(__('Temática'))
->required(),
Textarea::make('content')
->label(__('Escribe tu pregunta'))
->rows(10)
->required(),
])
->action(
function (array $data) {
$question = CreateQuestionAction::run($data + ['module_id' => $this->record->id]);

$this->dispatch('open-modal', id: 'thank-you-modal', parameters: [
'question' => $question,
]);
})
->createAnother(false)
->modalHeading('')
->icon('heroicon-o-plus')
];
}
Thanks!
3 Replies
toeknee
toeknee2w ago
I did it with afterValidate, I then check if any records exists, if they do they show a required field with the message in a placeholder for them to tick they are happy with the changes.
Xavi
XaviOP2w ago
But then the message will appear once they fill in the data. For example, if there is a limit of 10 questions and they have already done all 10, the message would appear after writing the question, which would result in poor user satisfaction.
toeknee
toeknee2w ago
That makes sense, then I am unsure
Want results from more Discord servers?
Add your server