-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow BatchAction without modal #4341
Comments
I worked on a workaround as I needed this feature. Add the following Javascript:
And then, add
It do the trick. |
But this is not compatible with |
I managed to change the The only option now would be to override the on click action |
If it can help, here is the workaround I'm using to not toggle the modal at all on defined batch actions. /**
* {@inheritDoc}
*/
public function configureActions(Actions $actions): Actions
{
return parent::configureActions($actions)
->addBatchAction(
Action::new('batchDownload', 'Download', 'fa fa-download')
->linkToCrudAction('batchDownload')
->setHtmlAttributes(['data-action-no-modal' => true]) // Do not display the confirmation modal.
)
;
}
/**
* {@inheritDoc}
*/
public function configureAssets(Assets $assets): Assets
{
return parent::configureAssets($assets)
->addWebpackEncoreEntry('app') // Adds the JS managing batch actions using the data-action-no-modal attribute.
;
} {# templates/bundles/EasyAdminBundle/crud/action.html.twig #}
{% if action.htmlAttributes['data-action-no-modal'] is defined %}
{% set htmlAttributes = action.htmlAttributes|filter((v, k) => k not in ['data-bs-toggle', 'data-bs-target']) %}
{% do action.setHtmlAttributes(htmlAttributes) %}
{% endif %}
{% include '@!EasyAdmin/crud/action.html.twig' %} // assets/app.js
// Manage batch actions using the data-action-no-modal attribute.
// @see vendor/easycorp/easyadmin-bundle/assets/js/app.js.
document.querySelectorAll('[data-action-no-modal]').forEach((dataActionBatch) => {
dataActionBatch.addEventListener('click', (event) => {
console.log('test');
event.preventDefault();
const actionElement = event.target.tagName.toUpperCase() === 'A' ? event.target : event.target.parentNode;
const selectedItems = document.querySelectorAll('input[type="checkbox"].form-batch-checkbox:checked');
// prevent double submission of the batch action form
actionElement.setAttribute('disabled', 'disabled');
const batchFormFields = {
'batchActionName': actionElement.getAttribute('data-action-name'),
'entityFqcn': actionElement.getAttribute('data-entity-fqcn'),
'batchActionUrl': actionElement.getAttribute('data-action-url'),
'batchActionCsrfToken': actionElement.getAttribute('data-action-csrf-token'),
};
selectedItems.forEach((item, i) => {
batchFormFields[`batchActionEntityIds[${i}]`] = item.value;
});
const batchForm = document.createElement('form');
batchForm.setAttribute('method', 'POST');
batchForm.setAttribute('action', actionElement.getAttribute('data-action-url'));
for (let fieldName in batchFormFields) {
const formField = document.createElement('input');
formField.setAttribute('type', 'hidden');
formField.setAttribute('name', fieldName);
formField.setAttribute('value', batchFormFields[fieldName]);
batchForm.appendChild(formField);
}
document.body.appendChild(batchForm);
batchForm.submit();
});
}); |
See #6375 |
Thanks for this proposal. I'm closing this issue in favor of #6674, which tries to solve this and other closely related issues. Thanks! |
A modal seems to be always mandatory for batchAction. I'd like to have an option for disable it.
It seems not possible actualy, it's done in ActionFactory.php#L134 which always overrides html attributes of the ActionDto.
Maybe related to #3455
Thanks
The text was updated successfully, but these errors were encountered: