Преглед изворни кода

[Form] Fix accessibility for file inputs

Victor Berchet пре 14 година
родитељ
комит
8d2974ce90

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/file_label.html.php

@@ -0,0 +1 @@
+<?php echo $view['form']->label($form['file']) ?>

+ 6 - 0
src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig

@@ -16,6 +16,12 @@
 {% endspaceless %}
 {% endblock form_label %}
 
+{% block file_label %}
+{% spaceless %}
+    {{ form_label(form.file) }}
+{% endspaceless %}
+{% endblock file_label %}
+
 {% block field_errors %}
 {% spaceless %}
     {% if errors|length > 0 %}

+ 19 - 0
tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php

@@ -404,4 +404,23 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
 '
         );
     }
+
+    public function testFileLabelAccessibility()
+    {
+        $form = $this->factory->createNamed('file', 'name');
+        $html = $this->renderRow($form->createView());
+
+        $this->assertMatchesXpath($html,
+'/div
+    [
+        ./label[@for="name_file"]
+        /following-sibling::div[@id="name"]
+            [
+                ./input[@id="name_file"][@type="file"]
+            ]
+    ]
+'
+        );
+    }
+
 }