Skip to content

Commit

Permalink
[Form] Fix collection rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jun 6, 2011
1 parent a1d866e commit bca17fe
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
@@ -0,0 +1 @@
<label <?php echo $view['form']->attributes() ?>><?php echo $view->escape($view['translator']->trans($label)) ?></label>

This file was deleted.

Expand Up @@ -41,6 +41,12 @@
{% endspaceless %}
{% endblock field_label %}

{% block collection_label %}
{% spaceless %}
<label {% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>
{% endspaceless %}
{% endblock collection_label %}

{% block attributes %}
{% spaceless %}
id="{{ id }}" name="{{ full_name }}"{% if read_only %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
Expand All @@ -50,11 +56,11 @@

{% block container_attributes %}
{% spaceless %}
id="{{ id }}"
id="{{ id }}"
{% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
{% endspaceless %}
{% endblock container_attributes %}

{% block field_widget %}
{% spaceless %}
{% set type = type|default('text') %}
Expand Down
40 changes: 40 additions & 0 deletions tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php
Expand Up @@ -133,6 +133,46 @@ public function testCollection()
);
}

public function testCollectionRow()
{
$collection = $this->factory->createNamedBuilder(
'collection',
'collection',
array('a', 'b'),
array('type' => 'text')
);

$form = $this->factory->createNamedBuilder('form', 'form')
->add($collection)
->getForm();

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/div
[
./input[@type="hidden"][@id="form__token"]
/following-sibling::div
[
./label[not(@for)]
/following-sibling::div
[
./div
[
./label[@for="form_collection_0"]
/following-sibling::input[@type="text"][@value="a"]
]
/following-sibling::div
[
./label[@for="form_collection_1"]
/following-sibling::input[@type="text"][@value="b"]
]
]
]
]
[count(.//input)=3]
'
);
}

public function testForm()
{
$form = $this->factory->createNamedBuilder('form', 'name')
Expand Down

0 comments on commit bca17fe

Please sign in to comment.