Skip to content

[Form] Form prototype rendered without default options #12997

Closed
@mvar

Description

@mvar

Form prototype is rendered with label even if it's disabled on collection item type.

Code:

class MyTextType extends AbstractType
{
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(['label' => false]);
    }

    public function getParent()
    {
        return 'text';
    }

    public function getName()
    {
        return 'my_text';
    }
}
class CustomType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add(
                'sample',
                'collection',
                [
                    'type' => 'my_text',
                    'allow_add' => true,
                    'required' => true,
                ]
            );
    }

    public function getName()
    {
        return 'custom';
    }
}

Controller:

$form = $this->createForm(new CustomType(), ['sample' => ['a', 'b']]);

Code above generates following form:

<form name="custom" method="post" action="xxx">
  <div id="custom">
    <div>                
      <label class="required">Sample</label>
      <div id="custom_sample" data-prototype="&lt;div&gt;                &lt;label for=&quot;custom_sample___name__&quot; class=&quot;required&quot;&gt;__name__label__&lt;/label&gt;&lt;input type=&quot;text&quot; id=&quot;custom_sample___name__&quot; name=&quot;custom[sample][__name__]&quot; required=&quot;required&quot; /&gt;&lt;/div&gt;">
        <div><input type="text" id="custom_sample_0" name="custom[sample][0]" required="required" value="a" /></div>
        <div><input type="text" id="custom_sample_1" name="custom[sample][1]" required="required" value="b" /></div>
      </div>
    </div>
    <input type="hidden" id="custom__token" name="custom[_token]" value="xxx" />
  </div>
</form>

Re-setting options while building CustomType form helps:

'options' => ['label' => false]

This renders both, input and prototype without label. But I think it should work without re-setting options.

Tested on Symfony 2.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions