Modal in form Resource

In my Filament project, I would like to introduce a modal in the function form of my Resource to indicate the available shortcodes that my writers can use. How can I insert this button that opens a modal?
3 Replies
tjodalv
tjodalv5mo ago
The best candidate for what you are trying to achieve would be hint action. Basically on any field you can define hint action that can open the modal with instructions:
Textarea::make('your_field_name')
->prefix('My field')
->hintAction(
Action::make('shortcode_instructions')
->modalContent(view('filament.pages.actions.shortcode-instructions'))
)
Textarea::make('your_field_name')
->prefix('My field')
->hintAction(
Action::make('shortcode_instructions')
->modalContent(view('filament.pages.actions.shortcode-instructions'))
)
More on hint actions here: https://filamentphp.com/docs/3.x/forms/actions#passing-multiple-hint-actions-to-a-field
Askancy
Askancy5mo ago
with:
RichEditor::make('testo')
->required()
->columnSpan('full')
->hintAction(
Action::make('shortcode_instructions')
->modalContent(view('filament.pages.actions.shortcode-instructions'))
),
RichEditor::make('testo')
->required()
->columnSpan('full')
->hintAction(
Action::make('shortcode_instructions')
->modalContent(view('filament.pages.actions.shortcode-instructions'))
),
I get the error: LOG.error: Filament\Forms\Components\Field::hintAction(): Argument #1 ($action) must be of type Filament\Forms\Components\Actions\Action|Closure, Filament\Tables\Actions\Action given
awcodes
awcodes5mo ago
You imported the wrong action. Change your use statement at the top of the file to use the forms components action.