You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.6KB

  1. {% form_theme form with easyadmin_config('design.form_theme') only %}
  2. {% set _entity_config = easyadmin_entity(app.request.query.get('entity')) %}
  3. {% trans_default_domain _entity_config.translation_domain %}
  4. {% set _trans_parameters = { '%entity_name%': _entity_config.name|trans, '%entity_label%': _entity_config.label|trans } %}
  5. {% extends _entity_config.templates.layout %}
  6. {% block body_id 'easyadmin-new-' ~ _entity_config.name %}
  7. {% block content_title %}
  8. {% apply spaceless %}
  9. {% set _default_title = 'new.page_title'|trans(_trans_parameters, 'EasyAdminBundle') %}
  10. {{ _entity_config.new.title is defined ? _entity_config.new.title|trans(_trans_parameters) : _default_title }}
  11. {% endapply %}
  12. {% endblock %}
  13. {% block content_footer_wrapper '' %}
  14. {% block main %}
  15. {% block entity_form %}
  16. {{ form(form) }}
  17. {% endblock entity_form %}
  18. {% endblock %}
  19. {% block head_stylesheets %}
  20. {{ parent() }}
  21. <link rel="stylesheet" href="{{ asset('bundles/lcshop/css/backend/adminlte/plugins/jquery-ui/jquery-ui.min.css') }}">
  22. {% endblock %}
  23. {% block plugin_javascript %}
  24. {{ parent() }}
  25. <script src="{{ asset('bundles/lcshop/js/backend/plugin/jquery-ui/jquery-ui.min.js') }}"></script>
  26. <script src="{{ asset('bundles/cksourceckfinder/ckfinder/ckfinder.js') }}"></script>
  27. {% endblock %}
  28. {% block script_javascript %}
  29. {{ parent() }}
  30. <script src="{{ asset('bundles/lcshop/js/backend/script/default/init-edit.js') }}"></script>
  31. {#
  32. <script type="text/javascript">
  33. $(function() {
  34. $('.new-form').areYouSure({ 'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}' });
  35. const entityForm = document.querySelector('form.new-form');
  36. const formSubmitButton = entityForm.querySelector('button[type="submit"]');
  37. const inputFieldsSelector = 'input,select,textarea';
  38. // Adding visual feedback for invalid fields: any ".form-group" with invalid fields
  39. // receives "has-error" class. The class is removed on click on the ".form-group"
  40. // itself to support custom/complex fields.
  41. formSubmitButton.addEventListener('click', function() {
  42. entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  43. if (!input.validity.valid) {
  44. const formGroup = input.closest('div.form-group');
  45. formGroup.classList.add('has-error');
  46. formGroup.addEventListener('click', function onFormGroupClick() {
  47. formGroup.classList.remove('has-error');
  48. formGroup.removeEventListener('click', onFormGroupClick);
  49. });
  50. }
  51. });
  52. });
  53. // forms with tabs require some special treatment for errors. The problem
  54. // is when the field with errors is included in a tab not currently visible.
  55. // Browser shows this error "An invalid form control with name='...' is not focusable."
  56. // So, the user clicks on Submit button, the form is not submitted and the error
  57. // is not displayed. This JavaScript code ensures that each tab shows a badge with
  58. // the number of errors in it.
  59. formSubmitButton.addEventListener('click', function() {
  60. const formTabPanes = entityForm.querySelectorAll('.tab-pane');
  61. if (0 === formTabPanes.length) {
  62. return;
  63. }
  64. let firstNavTabItemWithError = null;
  65. formTabPanes.forEach(function (tabPane) {
  66. let tabPaneNumErrors = 0;
  67. tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  68. if (!input.validity.valid) {
  69. tabPaneNumErrors++;
  70. }
  71. });
  72. let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]');
  73. let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger');
  74. if (null !== existingErrorBadge) {
  75. navTabItem.removeChild(existingErrorBadge);
  76. }
  77. if (tabPaneNumErrors > 0) {
  78. let newErrorBadge = document.createElement('span');
  79. newErrorBadge.classList.add('badge', 'badge-danger');
  80. newErrorBadge.title = 'form.tab.error_badge_title';
  81. newErrorBadge.textContent = tabPaneNumErrors;
  82. navTabItem.appendChild(newErrorBadge);
  83. if (null === firstNavTabItemWithError) {
  84. firstNavTabItemWithError = navTabItem;
  85. }
  86. }
  87. });
  88. if (firstNavTabItemWithError) {
  89. firstNavTabItemWithError.click();
  90. }
  91. });
  92. // prevent multiple form submissions to avoid creating duplicated entities
  93. entityForm.addEventListener('submit', function() {
  94. // this timeout is needed to include the disabled button into the submitted form
  95. setTimeout(function() {
  96. const submitButtons = entityForm.querySelectorAll('[type="submit"]');
  97. submitButtons.forEach(function(button) {
  98. button.setAttribute('disabled', 'disabled');
  99. });
  100. }, 1);
  101. }, false);
  102. });
  103. </script>
  104. #}
  105. {#{{ include('@EasyAdmin/default/includes/_select2_widget.html.twig') }}#}
  106. {% endblock %}