Selaa lähdekoodia

fixed xeditable boolean handling (#4415)

* fixed xeditable boolean handling

* fixed tests
Silas Joisten 8 vuotta sitten
vanhempi
commit
5d960b9801

+ 15 - 1
Resources/views/CRUD/base_list_field.html.twig

@@ -47,7 +47,21 @@ file that was distributed with this source code.
                     'code': admin.code(object)
                 })
             ) %}
-            <span {% block field_span_attributes %}class="x-editable" data-type="{{ xEditableType }}" data-value="{{ field_description.type == 'date' and value is not empty ? value.format('Y-m-d') : value }}" data-title="{{ field_description.label|trans({}, field_description.translationDomain) }}" data-pk="{{ admin.id(object) }}" data-url="{{ url }}" {% endblock %}>
+
+            {% if field_description == 'date' and value is not empty %}
+                {% set data_value = value.format('Y-m-d') %}
+            {% elseif field_description.type == 'boolean' and value is empty %}
+                {% set data_value = 0 %}
+            {% else %}
+                {% set data_value = value %}
+            {% endif %}
+
+            <span {% block field_span_attributes %}class="x-editable"
+                  data-type="{{ xEditableType }}"
+                  data-value="{{ data_value }}"
+                  data-title="{{ field_description.label|trans({}, field_description.translationDomain) }}"
+                  data-pk="{{ admin.id(object) }}"
+                  data-url="{{ url }}" {% endblock %}>
                 {{ block('field') }}
             </span>
         {% else %}

+ 2 - 2
Tests/Twig/Extension/SonataAdminExtensionTest.php

@@ -688,7 +688,7 @@ EOT
     <span
         class="x-editable"
         data-type="select"
-        data-value=""
+        data-value="0"
         data-title="Data"
         data-pk="12345"
         data-url="/core/set-object-field-value?context=list&amp;field=fd_name&amp;objectId=12345&amp;code=xyz"
@@ -708,7 +708,7 @@ EOT
     <span
         class="x-editable"
         data-type="select"
-        data-value=""
+        data-value="0"
         data-title="Data"
         data-pk="12345"
         data-url="/core/set-object-field-value?context=list&amp;field=fd_name&amp;objectId=12345&amp;code=xyz"