選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

120 行
5.1KB

  1. {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
  2. {# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
  3. {% set form = edit_form %}
  4. {% extends '@LcSov/adminlte/crud/layout_form.html.twig' %}
  5. {% block body_id 'ea-edit-' ~ entity.name ~ '-' ~ entity.primaryKeyValue %}
  6. {% block body_class 'ea-edit ea-edit-' ~ entity.name %}
  7. {% block content_title %}
  8. {{ 'edit'|sov_trans_admin_title(ea.getEntity().getFqcn(), {id: ea.getEntity().getInstance().getId()}) }}
  9. {% endblock %}
  10. {% block delete_form %}
  11. {{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', { entity_id: entity.primaryKeyValue }, with_context = false) }}
  12. {% endblock delete_form %}
  13. {#
  14. {% block body_javascript %}
  15. {{ parent() }}
  16. <script type="text/javascript">
  17. $(function () {
  18. $('.ea-edit-form').areYouSure({'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}'});
  19. const entityForm = document.querySelector('form.ea-edit-form');
  20. const inputFieldsSelector = 'input,select,textarea';
  21. // Adding visual feedback for invalid fields: any ".form-group" with invalid fields
  22. // receives "has-error" class. The class is removed on click on the ".form-group"
  23. // itself to support custom/complex fields.
  24. entityForm.addEventListener('submit', function (submitEvent) {
  25. entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  26. if (!input.validity.valid) {
  27. const formGroup = input.closest('div.form-group');
  28. formGroup.classList.add('has-error');
  29. formGroup.addEventListener('click', function onFormGroupClick() {
  30. formGroup.classList.remove('has-error');
  31. formGroup.removeEventListener('click', onFormGroupClick);
  32. });
  33. }
  34. });
  35. const eaEvent = new CustomEvent('ea.form.submit', {
  36. cancelable: true,
  37. detail: {page: 'edit', form: entityForm}
  38. });
  39. const eaEventResult = document.dispatchEvent(eaEvent);
  40. if (false === eaEventResult) {
  41. submitEvent.preventDefault();
  42. submitEvent.stopPropagation();
  43. }
  44. });
  45. // forms with tabs require some special treatment for errors. The problem
  46. // is when the field with errors is included in a tab not currently visible.
  47. // Browser shows this error "An invalid form control with name='...' is not focusable."
  48. // So, the user clicks on Submit button, the form is not submitted and the error
  49. // is not displayed. This JavaScript code ensures that each tab shows a badge with
  50. // the number of errors in it.
  51. entityForm.addEventListener('submit', function () {
  52. const formTabPanes = entityForm.querySelectorAll('.tab-pane');
  53. if (0 === formTabPanes.length) {
  54. return;
  55. }
  56. let firstNavTabItemWithError = null;
  57. formTabPanes.forEach(function (tabPane) {
  58. let tabPaneNumErrors = 0;
  59. tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  60. if (!input.validity.valid) {
  61. tabPaneNumErrors++;
  62. }
  63. });
  64. let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]');
  65. let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger');
  66. if (null !== existingErrorBadge) {
  67. navTabItem.removeChild(existingErrorBadge);
  68. }
  69. if (tabPaneNumErrors > 0) {
  70. let newErrorBadge = document.createElement('span');
  71. newErrorBadge.classList.add('badge', 'badge-danger');
  72. newErrorBadge.title = 'form.tab.error_badge_title';
  73. newErrorBadge.textContent = tabPaneNumErrors;
  74. navTabItem.appendChild(newErrorBadge);
  75. if (null === firstNavTabItemWithError) {
  76. firstNavTabItemWithError = navTabItem;
  77. }
  78. }
  79. });
  80. if (firstNavTabItemWithError) {
  81. firstNavTabItemWithError.click();
  82. }
  83. });
  84. $('.action-delete').on('click', function (e) {
  85. e.preventDefault();
  86. const formAction = $(this).attr('formaction');
  87. $('#modal-delete').modal({backdrop: true, keyboard: true})
  88. .off('click', '#modal-delete-button')
  89. .on('click', '#modal-delete-button', function () {
  90. $('#delete-form').attr('action', formAction).trigger('submit');
  91. });
  92. });
  93. });
  94. </script>
  95. <
  96. {% endblock %}
  97. #}