EasyAdminBundle
EasyAdminBundle copied to clipboard
[RFC][3.x] Open to enable/disable "New" and "Edit" action via modals
Short description of what this feature will allow to do: Add an option to enable "new" and "edit" actions in modals.
Sometimes, a crud controller has only few fields, and a dedicated empty 'new' page for just few fields doesn't seem right. In this case, in the crud controller you can just enable 'new' and 'edit' actions in modals instead.
Example of how to use this feature
To enable the feature, all you have to do is :
public function configureCrud(Crud $crud): Crud
{
return $crud->showFormsInModal(true);
}
And behind the scenes, this would happen:
If showFormsInModal is true,
- the 'crud/new' is replaced by one that returns only the form (nothing else)
- in 'crud/index', include a twig template to load the modal div to the dom
{{ include('@EasyAdmin/crud/includes/_form_modal.html.twig') }} - update edit and new actions to add some data (so we can replace the href / link with an action to load the modal content and show it)
$action
->addCssClass('modal')
->getAsDto()->addHtmlAttributes([
'data-bs-toggle' => 'modal',
'data-bs-target' => '#modal-new',
]);
- in app.js, add the mechanism that performs a xhr to the 'link' on the button and load the content to the modal
this would be a great feature but you would also need to:
- add the attribute "action" to the
- ajax validation of the form
we're working on such feature as we need it for a project, we'll try to keep you updated if you're still interested