Display existing form in action modal

Hey all! I was tasked to create a composite resource from two existing Models. Each model already has its own associated resource, but configuring these "base" models is an advanced feature. The composite resource should allow users to supply a subset of the parameters and let the application automatically fill the rest. In my current solution, I have achieved this by spreading the ModuleResource form fields and using an Agent Repeater which only exposes a subset of the parameters. I want users to still be able to access the "advanced" properties of the AgentResource by clicking on an action in my repeater. I was able to redirect users to the AgentResource, but ideally I want to display the resources form inside a modal. Is there a way to achieve this? Thanks for your help in advance! Tl;Dr: Display an existing resource form in the modal triggered by an action on a repeater.
3 Replies
InternalError
InternalErrorOP3mo ago
Below you can find my current solution - the relevant section is the "->extraItemActions" block:
public static function form(Form $form): Form
{
return $form
->schema([
...ModuleResource::form($form)->getComponents(),
Repeater::make('agents')
->relationship('agents')
->columnSpanFull()
->schema([
Forms\Components\Textarea::make('instructions')
->required()
->label('Instructions')
->helperText('Guidelines that the agent follows to generate responses')
->placeholder('e.g. You are a helpful university tutor providing aid for students tasked with programming ...'),
Forms\Components\Select::make('openai_language_model')
->required()
->options(fn () => collect(OpenAI::models())->pluck('name', 'name'))
->helperText(fn () => new HtmlString(collect(OpenAI::models())
->map(fn ($model) => "<strong>{$model->name}</strong> - Input: \${$model->input} / 1M tokens, Output: \${$model->output} / 1M tokens")
->join('<br>')))
->label('OpenAI Language Model'),
])
->extraItemActions([
Forms\Components\Actions\Action::make('viewAgentForm')
->icon('heroicon-o-cube')
->label('View Advanced Agent Form')
->modalHeading('Agent Form')
->modalDescription('Edit the advanced details for the agent.')
->modalWidth('lg')
->url(fn ($record) => AgentResource::getUrl('edit', [$record]), true),
]
)
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
...ModuleResource::form($form)->getComponents(),
Repeater::make('agents')
->relationship('agents')
->columnSpanFull()
->schema([
Forms\Components\Textarea::make('instructions')
->required()
->label('Instructions')
->helperText('Guidelines that the agent follows to generate responses')
->placeholder('e.g. You are a helpful university tutor providing aid for students tasked with programming ...'),
Forms\Components\Select::make('openai_language_model')
->required()
->options(fn () => collect(OpenAI::models())->pluck('name', 'name'))
->helperText(fn () => new HtmlString(collect(OpenAI::models())
->map(fn ($model) => "<strong>{$model->name}</strong> - Input: \${$model->input} / 1M tokens, Output: \${$model->output} / 1M tokens")
->join('<br>')))
->label('OpenAI Language Model'),
])
->extraItemActions([
Forms\Components\Actions\Action::make('viewAgentForm')
->icon('heroicon-o-cube')
->label('View Advanced Agent Form')
->modalHeading('Agent Form')
->modalDescription('Edit the advanced details for the agent.')
->modalWidth('lg')
->url(fn ($record) => AgentResource::getUrl('edit', [$record]), true),
]
)
]);
}
InternalError
InternalErrorOP3mo ago
When I remove the ->url call, I get this modal currently. I am not sure how to set the modals content to the AgentResource form.
No description

Did you find this page helpful?