You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Since 4.2.2 I noticed that when my form handles the request and I check that the form is valid it returns an error for one of my custom fields. This field returns an array of values, so its form name is as following name="example[]" this is commonly used for things like select fields which sources are not predetermined (reason why not using ChoiceType). For example a select2 type with sources comming from an ajax call.
How to reproduce
Create a form with a custom type that has name="example[]" as a field name. $_POST shows that the value is indeed there as an array, however the form itself does not recognise it as such. When removing the [] it works but as a single value field.
Possible Solution
For now fixing composer to use version 4.2.1 fixes this issue, but this is indeed no fix.
Additional context
class Select2Type extends AbstractType implements DataTransformerInterface
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'selected' => array(),
'compound' => false,
));
$resolver->setAllowedTypes('selected', array('null', 'array', '\Traversable'));
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addViewTransformer($this);
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['choices'] = $options['selected'];
}
public function getBlockPrefix()
{
return 'select2';
}
public function transform($value)
{
if(!is_array($value)){
return [];
}
return array_values($value);
}
public function reverseTransform($value)
{
if(!is_array($value)){
return [$value];
}
return array_values($value);
}
}
Symfony version(s) affected: 4.2.2 and up
Description
Since 4.2.2 I noticed that when my form handles the request and I check that the form is valid it returns an error for one of my custom fields. This field returns an array of values, so its form name is as following
name="example[]"
this is commonly used for things like select fields which sources are not predetermined (reason why not using ChoiceType). For example a select2 type with sources comming from an ajax call.How to reproduce
name="example[]"
as a field name. $_POST shows that the value is indeed there as an array, however the form itself does not recognise it as such. When removing the [] it works but as a single value field.Possible Solution
For now fixing composer to use version 4.2.1 fixes this issue, but this is indeed no fix.
Additional context
// The field template
The text was updated successfully, but these errors were encountered: