Sfoglia il codice sorgente

Extend money_widget and percent_widget

Input fields are streched to 100% width in the new SonataAdminBundle, but this
doesn't take into account any extra text such as percentage signs or currency
symbols, causing either the symbol or the input field to be pushed to the next
line.

Using Bootstrap's input-group we can prevent this, and also render the symbol
in a nice little box.

The money widget respects the money_pattern variable, so the currency symbol
will be rendered before or after the input, depending on the locale or the
given money_pattern.
Nic Wortel 10 anni fa
parent
commit
62488eb881
1 ha cambiato i file con 29 aggiunte e 0 eliminazioni
  1. 29 0
      Resources/views/Form/form_admin_fields.html.twig

+ 29 - 0
Resources/views/Form/form_admin_fields.html.twig

@@ -28,6 +28,35 @@ file that was distributed with this source code.
     {{ parent() }}
 {% endblock textarea_widget %}
 
+{% block money_widget -%}
+    {% if money_pattern == '{{ widget }}' %}
+        {{- block('form_widget_simple') -}}
+    {% else %}
+        {% set currencySymbol = money_pattern|replace({'{{ widget }}': ''})|trim %}
+        {% if money_pattern matches '/^{{ widget }}/' %}
+            <div class="input-group">
+                {{- block('form_widget_simple') -}}
+                <span class="input-group-addon">{{ currencySymbol }}</span>
+            </div>
+        {% elseif money_pattern matches '/{{ widget }}$/' %}
+            <div class="input-group">
+                <span class="input-group-addon">{{ currencySymbol }}</span>
+                {{- block('form_widget_simple') -}}
+            </div>
+        {% endif %}
+    {% endif %}
+{%- endblock money_widget %}
+
+{% block percent_widget %}
+    {% spaceless %}
+        {% set type = type|default('text') %}
+        <div class="input-group">
+            {{ block('form_widget_simple') }}
+            <span class="input-group-addon">%</span>
+        </div>
+    {% endspaceless %}
+{% endblock percent_widget %}
+
 {# Labels #}
 {% block form_label %}
 {% spaceless %}