From 693d1ec2379f8fbfadfa0149564f3a3c6b41ffc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20G=C3=B3recki?= Date: Wed, 18 Jan 2012 10:37:34 +0100 Subject: [PATCH] [Form] Do not render default ID attribute on empty form name Bug fix: no Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: - Todo: - This is cleanup after enabling empty form names, now form with empty name will not render the default `id="form"` container attribute. Developers can extend/override this behaviour by standard form theming methods. --- .../Twig/Resources/views/Form/form_div_layout.html.twig | 2 +- .../Resources/views/Form/container_attributes.html.php | 2 +- src/Symfony/Component/Form/Extension/Core/Type/FieldType.php | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 09d751794c1d..3ba5fc5f4bd5 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -287,7 +287,7 @@ {% block widget_container_attributes %} {% spaceless %} - id="{{ id }}" + {% if id is not empty %}id="{{ id }}" {% endif %} {% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %} {% endspaceless %} {% endblock widget_container_attributes %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/container_attributes.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/container_attributes.html.php index 24d6769fe32c..a36cfbbdfc46 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/container_attributes.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/container_attributes.html.php @@ -1,2 +1,2 @@ -id="escape($id) ?>" +id="escape($id) ?>" $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?> diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php b/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php index e222d61b6480..05aaf230f1db 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php @@ -86,9 +86,7 @@ public function buildView(FormView $view, FormInterface $form) $fullName = $name; } } else { - // If this form node have empty name, set id to `form` - // to avoid rendering `id=""` in html structure - $id = $name ?: 'form'; + $id = $name; $fullName = $name; }