Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Form element Checkbox

I have some problems setting a checkbox bind with an entity.

I want my checkbox value to 1 (true) and the checkbox is checked only if the value in model is true. but whatever the value in the model, the checkbox will be checked, and the value will be 1 or nothing (0) depending the entity value.

that's quite problematicin many situation.

here is my checkbox definition

        $visibility = new Check(self::VISIBILITY);
        $visibility->setLabel('Visible');
        $visibility->setDefault(true);
        $this->add($visibility);

in the controller I search for my entity and I do a $form->setEntity($entity) to bind the values. all of them worked (I had to did a manual trick to populate multi select though), but checkboxes donesn't work at all.

there should be a setValue on Check Element to set the value, and check it if the value match with the default/entity's value.

I don't know how i could quickly fix this.



3.7k
Accepted
answer

setting attribute value worked ...

I don't think it's really an intuitive way but that works.