Validate a field inside a modal
I'd like to know if there is a way to validate a field inside a modal window. (which is of course called from an action).
I have a
This is my code so far:
I have a
SelectSelect field that has to be filled in, before executing the action. How can I achieve this?This is my code so far:
Action::make('generate')
->link()
->slideOver()
->icon('heroicon-o-sparkles')
->modalWidth('3xl')
->modalHeading('Generate')
->modalSubmitActionLabel('Save')
->closeModalByClickingAway(false)
->form([
Select::make('prompt')
->label('Prompt')
->required()
->reactive()
->searchable()
->preload()
->options(Prompt::all()->pluck('name', 'id')),
RichEditor::make('job_description_original')
->disableAllToolbarButtons()
->label('Origineel')
->default(fn ($livewire) => $livewire->data['job_description']),
Actions::make([
Action::make('generate_alternative')
->label('Generate')
->action(function ($get, $set, $record, $livewire) {
// MAKE SURE THERE IS A PROMPT SELECTED?
$result = GenerateSummary::make()->handle(
$get('prompt'),
$record->job_title,
$get('job_description_original')
);
$set('job_description_alt', $result);
}),
]),
RichEditor::make('job_description_alt')
->disableAllToolbarButtons()
->hiddenLabel(),
])
->action(function (array $data, $set): void {
$set('job_description', $data['job_description_alt']);
}),Action::make('generate')
->link()
->slideOver()
->icon('heroicon-o-sparkles')
->modalWidth('3xl')
->modalHeading('Generate')
->modalSubmitActionLabel('Save')
->closeModalByClickingAway(false)
->form([
Select::make('prompt')
->label('Prompt')
->required()
->reactive()
->searchable()
->preload()
->options(Prompt::all()->pluck('name', 'id')),
RichEditor::make('job_description_original')
->disableAllToolbarButtons()
->label('Origineel')
->default(fn ($livewire) => $livewire->data['job_description']),
Actions::make([
Action::make('generate_alternative')
->label('Generate')
->action(function ($get, $set, $record, $livewire) {
// MAKE SURE THERE IS A PROMPT SELECTED?
$result = GenerateSummary::make()->handle(
$get('prompt'),
$record->job_title,
$get('job_description_original')
);
$set('job_description_alt', $result);
}),
]),
RichEditor::make('job_description_alt')
->disableAllToolbarButtons()
->hiddenLabel(),
])
->action(function (array $data, $set): void {
$set('job_description', $data['job_description_alt']);
}),