Answer the question
In order to leave comments, you need to log in
Why doesn't the form validate when using the "collection" type with text values?
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('description', 'text')
->add('coordinates', 'collection', array(
'type' => 'text'
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver){
$resolver->setDefaults(array(
'allow_extra_fields' => true,
'csrf_protection' => false,
'data_class' => '\AppBundle\Entity\Marker'
));
}
$dataMarker = array(
'description' => "asdasdada",
'coordinates' => array(123123, 234234)
);
$form = $this->get('form.factory')->create(new MarkerType(), new Marker());
$form->submit($dataMarker);
Answer the question
In order to leave comments, you need to log in
It turned out that you need to specify "allow_extra_fields" directly in the field initialization array with the collection type:
->add('coordinates', 'collection', array(
'type' => 'text',
'allow_add' => true,
'allow_extra_fields' => true
));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question