Sfoglia il codice sorgente

[Bridge/Twig] Add required class to labels that match required fields

Jordi Boggiano 14 anni fa
parent
commit
52fdd53af8

+ 3 - 0
src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

@@ -184,6 +184,9 @@
 
 {% block field_label %}
 {% spaceless %}
+    {% if required %}
+        {% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %}
+    {% endif %}
     <label for="{{ id }}"{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>
 {% endspaceless %}
 {% endblock field_label %}

+ 2 - 2
tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

@@ -209,7 +209,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         $this->assertMatchesXpath($html,
 '/label
     [@for="na&me"]
-    [@class="my&class"]
+    [@class="my&class required"]
 '
         );
     }
@@ -228,7 +228,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         $this->assertMatchesXpath($html,
 '/label
     [@for="na&me"]
-    [@class="my&class"]
+    [@class="my&class required"]
     [.="[trans]Custom label[/trans]"]
 '
         );