Description
Hi,
I'm currently updating my code to symfony 2.7 and I saw a weird behavior with choice field form with boolean value.
Here is my form class:
<?php
namespace Icap\DropzoneBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class DropzoneCommonType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('peerReview', 'choice', array(
'required' => true,
'choices' => array(
'Standard evaluation' => false,
'Peer review evaluation' => true
),
'choices_as_values' => true,
'expanded' => true,
'multiple' => false
));
}
public function getName()
{
return 'icap_dropzone_common_form';
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Icap\DropzoneBundle\Entity\Dropzone',
'language' => 'en',
'translation_domain' => 'icap_dropzone',
'date_format' => DateType::HTML5_FORMAT,
)
);
}
}
And how the field is displayed, pretty classic:
{{ form_row(form.peerReview, {'label_attr': {'style': 'display: none;'}}) }}
But at the display of the form the field doesn't have its value checked, the radio button here.
The radio button is checked at the display of the form only after submitting it.
I checked in the debug bar to see what was in the form and I found what I think it's an error.
Before submitting the form the value, and the data, of the field peerReview is 1, and after submitting the value, and the data to, is true. I checked in my object and the attribute is a boolean with true as value.
After submitting the value is boolean, what I expect it to be, but before submission it's an integer.
Is it a bug or am I missing something?