Browse Source

sonata_type_choice_field_mask_widget : javascript change

- Hide all fields if no item is selected
- Use jQuery instead of $
Jérôme FIX 11 years ago
parent
commit
895e46acb8
1 changed files with 12 additions and 11 deletions
  1. 12 11
      Resources/views/Form/form_admin_fields.html.twig

+ 12 - 11
Resources/views/Form/form_admin_fields.html.twig

@@ -384,15 +384,15 @@ file that was distributed with this source code.
 {% block sonata_type_choice_field_mask_widget %}
     {{ block('choice_widget') }}
     {% set main_form_name = id|slice(0, id|length - name|length) %}
-    <script type="text/javascript">
-        $(document).ready(function() {
+    <script>
+        jQuery(document).ready(function() {
             var allFields = {{ all_fields|json_encode|raw }};
             var map = {{ map|json_encode|raw }};
 
-            showMaskChoiceEl = $('#{{ main_form_name }}{{ name }}');
-            console.log(showMaskChoiceEl)
+            showMaskChoiceEl = jQuery('#{{ main_form_name }}{{ name }}');
+
             showMaskChoiceEl.on('change', function () {
-                choice_field_mask_show($(this).val());
+                choice_field_mask_show(jQuery(this).val());
             });
 
             function choice_field_mask_show(val)
@@ -402,20 +402,21 @@ file that was distributed with this source code.
 
                 };
                 if (map[val] == undefined) {
-                    $.each(allFields, function (i, field) {
-                        $(controlGroupIdFunc(field)).show();
+                    jQuery.each(allFields, function (i, field) {
+                        jQuery(controlGroupIdFunc(field)).hide();
                     });
                     return;
                 }
 
-                $.each(allFields, function (i, field) {
-                    $(controlGroupIdFunc(field)).hide();
+                jQuery.each(allFields, function (i, field) {
+                    jQuery(controlGroupIdFunc(field)).hide();
                 });
-                $.each(map[val], function (i, field) {
-                    $(controlGroupIdFunc(field)).show();
+                jQuery.each(map[val], function (i, field) {
+                    jQuery(controlGroupIdFunc(field)).show();
                 });
             }
             choice_field_mask_show(showMaskChoiceEl.val());
         });
+
     </script>
 {% endblock %}