|
- {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
- {# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
- {% set form = edit_form %}
- {% extends '@LcSov/adminlte/crud/_form.html.twig' %}
-
- {% block body_id 'ea-edit-' ~ entity.name ~ '-' ~ entity.primaryKeyValue %}
- {% block body_class 'ea-edit ea-edit-' ~ entity.name %}
-
- {% block content_title %}
- {%- apply spaceless -%}
- {{ ea.crud.customPageTitle is null
- ? (ea.crud.defaultPageTitle|trans(ea.i18n.translationParameters, 'EasyAdminBundle'))|raw
- : ea.crud.customPageTitle|trans(ea.i18n.translationParameters)|raw }}
- {%- endapply -%}
- {% endblock %}
-
- {% block delete_form %}
- {{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', { entity_id: entity.primaryKeyValue }, with_context = false) }}
- {% endblock delete_form %}
-
- {#
-
- {% block body_javascript %}
- {{ parent() }}
-
- <script type="text/javascript">
- $(function () {
- $('.ea-edit-form').areYouSure({'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}'});
-
- const entityForm = document.querySelector('form.ea-edit-form');
- const inputFieldsSelector = 'input,select,textarea';
-
- // Adding visual feedback for invalid fields: any ".form-group" with invalid fields
- // receives "has-error" class. The class is removed on click on the ".form-group"
- // itself to support custom/complex fields.
- entityForm.addEventListener('submit', function (submitEvent) {
- entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) {
- if (!input.validity.valid) {
- const formGroup = input.closest('div.form-group');
-
- formGroup.classList.add('has-error');
-
- formGroup.addEventListener('click', function onFormGroupClick() {
- formGroup.classList.remove('has-error');
- formGroup.removeEventListener('click', onFormGroupClick);
- });
- }
- });
-
- const eaEvent = new CustomEvent('ea.form.submit', {
- cancelable: true,
- detail: {page: 'edit', form: entityForm}
- });
- const eaEventResult = document.dispatchEvent(eaEvent);
- if (false === eaEventResult) {
- submitEvent.preventDefault();
- submitEvent.stopPropagation();
- }
- });
-
- // forms with tabs require some special treatment for errors. The problem
- // is when the field with errors is included in a tab not currently visible.
- // Browser shows this error "An invalid form control with name='...' is not focusable."
- // So, the user clicks on Submit button, the form is not submitted and the error
- // is not displayed. This JavaScript code ensures that each tab shows a badge with
- // the number of errors in it.
- entityForm.addEventListener('submit', function () {
- const formTabPanes = entityForm.querySelectorAll('.tab-pane');
- if (0 === formTabPanes.length) {
- return;
- }
-
- let firstNavTabItemWithError = null;
-
- formTabPanes.forEach(function (tabPane) {
- let tabPaneNumErrors = 0;
- tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) {
- if (!input.validity.valid) {
- tabPaneNumErrors++;
- }
- });
-
- let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]');
- let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger');
- if (null !== existingErrorBadge) {
- navTabItem.removeChild(existingErrorBadge);
- }
-
- if (tabPaneNumErrors > 0) {
- let newErrorBadge = document.createElement('span');
- newErrorBadge.classList.add('badge', 'badge-danger');
- newErrorBadge.title = 'form.tab.error_badge_title';
- newErrorBadge.textContent = tabPaneNumErrors;
-
- navTabItem.appendChild(newErrorBadge);
-
- if (null === firstNavTabItemWithError) {
- firstNavTabItemWithError = navTabItem;
- }
- }
- });
-
- if (firstNavTabItemWithError) {
- firstNavTabItemWithError.click();
- }
- });
-
- $('.action-delete').on('click', function (e) {
- e.preventDefault();
- const formAction = $(this).attr('formaction');
-
- $('#modal-delete').modal({backdrop: true, keyboard: true})
- .off('click', '#modal-delete-button')
- .on('click', '#modal-delete-button', function () {
- $('#delete-form').attr('action', formAction).trigger('submit');
- });
- });
- });
- </script>
- <
-
- {% endblock %}
- #}
|