Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form][2.7] Preselection of choice field with boolean value #14712

Copy link
Copy link
Closed
@maxailloud

Description

@maxailloud
Issue body actions

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.