Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

130 rindas
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. {% endblock %}
  27. {% block script_javascript %}
  28. {{ parent() }}
  29. <script src="{{ asset('bundles/lcshop/js/backend/script/default/init-edit.js') }}"></script>
  30. {#
  31. <script type="text/javascript">
  32. $(function() {
  33. $('.new-form').areYouSure({ 'message': '{{ 'form.are_you_sure'|trans({}, 'EasyAdminBundle')|e('js') }}' });
  34. const entityForm = document.querySelector('form.new-form');
  35. const formSubmitButton = entityForm.querySelector('button[type="submit"]');
  36. const inputFieldsSelector = 'input,select,textarea';
  37. // Adding visual feedback for invalid fields: any ".form-group" with invalid fields
  38. // receives "has-error" class. The class is removed on click on the ".form-group"
  39. // itself to support custom/complex fields.
  40. formSubmitButton.addEventListener('click', function() {
  41. entityForm.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  42. if (!input.validity.valid) {
  43. const formGroup = input.closest('div.form-group');
  44. formGroup.classList.add('has-error');
  45. formGroup.addEventListener('click', function onFormGroupClick() {
  46. formGroup.classList.remove('has-error');
  47. formGroup.removeEventListener('click', onFormGroupClick);
  48. });
  49. }
  50. });
  51. });
  52. // forms with tabs require some special treatment for errors. The problem
  53. // is when the field with errors is included in a tab not currently visible.
  54. // Browser shows this error "An invalid form control with name='...' is not focusable."
  55. // So, the user clicks on Submit button, the form is not submitted and the error
  56. // is not displayed. This JavaScript code ensures that each tab shows a badge with
  57. // the number of errors in it.
  58. formSubmitButton.addEventListener('click', function() {
  59. const formTabPanes = entityForm.querySelectorAll('.tab-pane');
  60. if (0 === formTabPanes.length) {
  61. return;
  62. }
  63. let firstNavTabItemWithError = null;
  64. formTabPanes.forEach(function (tabPane) {
  65. let tabPaneNumErrors = 0;
  66. tabPane.querySelectorAll(inputFieldsSelector).forEach(function (input) {
  67. if (!input.validity.valid) {
  68. tabPaneNumErrors++;
  69. }
  70. });
  71. let navTabItem = entityForm.querySelector('.nav-item a[href="#' + tabPane.id + '"]');
  72. let existingErrorBadge = navTabItem.querySelector('span.badge.badge-danger');
  73. if (null !== existingErrorBadge) {
  74. navTabItem.removeChild(existingErrorBadge);
  75. }
  76. if (tabPaneNumErrors > 0) {
  77. let newErrorBadge = document.createElement('span');
  78. newErrorBadge.classList.add('badge', 'badge-danger');
  79. newErrorBadge.title = 'form.tab.error_badge_title';
  80. newErrorBadge.textContent = tabPaneNumErrors;
  81. navTabItem.appendChild(newErrorBadge);
  82. if (null === firstNavTabItemWithError) {
  83. firstNavTabItemWithError = navTabItem;
  84. }
  85. }
  86. });
  87. if (firstNavTabItemWithError) {
  88. firstNavTabItemWithError.click();
  89. }
  90. });
  91. // prevent multiple form submissions to avoid creating duplicated entities
  92. entityForm.addEventListener('submit', function() {
  93. // this timeout is needed to include the disabled button into the submitted form
  94. setTimeout(function() {
  95. const submitButtons = entityForm.querySelectorAll('[type="submit"]');
  96. submitButtons.forEach(function(button) {
  97. button.setAttribute('disabled', 'disabled');
  98. });
  99. }, 1);
  100. }, false);
  101. });
  102. </script>
  103. #}
  104. {#{{ include('@EasyAdmin/default/includes/_select2_widget.html.twig') }}#}
  105. {% endblock %}