Select field create new option in modal but using url of existing resource/create - Action in modal

Hello. I have a select field where user can select from all the created record_types. I have added a button to create a new one (a new record_type) without leaving the form. The problem is that I do not want to use the ->form( because the record_type resource has more that 30 fields. How can I make this code to execute as it does but in a MODAL?
Select::make('record_type_id')
->label(__('record_type'))
->options(RecordType::all()->pluck('description', 'id'))
->hintAction(
Action::make('record_type_create')
->url('/record-types/create')
->icon('heroicon-m-plus')
->modalContent()
->requiresConfirmation()
)
Select::make('record_type_id')
->label(__('record_type'))
->options(RecordType::all()->pluck('description', 'id'))
->hintAction(
Action::make('record_type_create')
->url('/record-types/create')
->icon('heroicon-m-plus')
->modalContent()
->requiresConfirmation()
)
It opens the record_type create form, but it is not MODAL. Even if I use ->url('/record-types/create' , true) it opens in a new tab, but it still is NOT A MODAL. Any idea of how to make it work as a modal?? The idea is, of course, that when creating dossiers, to create a new record_type which is not yet created and therefore not in the select list, be able to create that as modal and REFRESH the list afterwards. Tks.
No description
11 Replies
Patrick Boivin
Patrick Boivin16mo ago
I see a call to ->url()... are you trying to open the URL in the modal? It's not going to work, as ->url() makes a regular <a> tag
Albert Lens
Albert LensOP16mo ago
Ok. I did not want to use url(). That is the only way I have found to let the user go to a different resource/create FORM without leaving the form he is at then. The real thing is I want to open a standard create FORM of a filament resource from within and in MODAL. Is that possible? And how? Thank you very much.
Patrick Boivin
Patrick Boivin16mo ago
Yeah, I don't think this is possible out of the box. The only way I can think of is to use ->form() on the action. You may be able to share the form schema with the original resource via the static form() method.
Albert Lens
Albert LensOP16mo ago
Please, could you link me to an example? Any hint of where to begin? I need to open the CreateReportType.php file in app\Filament\Resources\RecordTypeResource\Pages Even if it is not in a modal. The most important fact, besides the modal, is that when created the new recordtype the launcher button gets the response.
Albert Lens
Albert LensOP16mo ago
I suppose you mean this:
->hintAction(
Action::make('record_type_create')
// ->url('/record-types/create',true)
->form([
TextInput::make('description')
->label(__('description'))
->autofocus()
->required()
->unique(ignoreRecord: true)
->placeholder(__('description'))
->extraInputAttributes(['style' => 'font-weight: bolder; font-size: 1.1rem;']),
Toggle::make('enabled')->default(true)->hiddenOn(['create'])
->onColor('success')
->offColor('gray')
->hiddenOn(['view','create']),
])
->hintAction(
Action::make('record_type_create')
// ->url('/record-types/create',true)
->form([
TextInput::make('description')
->label(__('description'))
->autofocus()
->required()
->unique(ignoreRecord: true)
->placeholder(__('description'))
->extraInputAttributes(['style' => 'font-weight: bolder; font-size: 1.1rem;']),
Toggle::make('enabled')->default(true)->hiddenOn(['create'])
->onColor('success')
->offColor('gray')
->hiddenOn(['view','create']),
])
No description
Patrick Boivin
Patrick Boivin16mo ago
Yes, exactly this. You can recreate your form there or share some fields between the modal and the Resource class. It's up to you how you want to do that.
Albert Lens
Albert LensOP16mo ago
Ok. The only problem is that the form has a Repeater with a relationship, and that is throwing an error.
Patrick Boivin
Patrick Boivin16mo ago
Yeah, sounds like a complex form... not sure a modal is the best solution personally but I understand that the new tab is not perfect either.
Albert Lens
Albert LensOP16mo ago
Without the repeater part it works fine. When I put the repeater part, it halts and gives the error: Call to undefined method App\Models\Dossier::actions() actions is the name of the repeater and relationship.
awcodes
awcodes16mo ago
you're not going to be able to call it actions, because forms have an internal actions method used to register form actions.
Albert Lens
Albert LensOP16mo ago
Anyway, I have changed the name of the relationship to recordTypeActions and it still is giving the same error. It looks as if ->form() does NOT admit Repeater at all. It is a real pity. Call to undefined method App\Models\Dossier::recordTypeActions()
Want results from more Discord servers?
Add your server