Closed
Description
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="<div> <label for="custom_sample___name__" class="required">__name__label__</label><input type="text" id="custom_sample___name__" name="custom[sample][__name__]" required="required" /></div>">
<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