2
votes

Is there a way to use the checkbox form type with a field that has been set to string?

This field can hold many values, it can be used to input data as a textfield or as a checkbox.

I have a event listener on the formtype to check if it should be a checkbox or text field.

/Entity.php

/**
 * @var string 
 *
 * @ORM\Column(name="value", type="string", length=200, nullable=true)
 */
private $value;

formtype.php

$form->add('value', 'checkbox', array(

))

Error

Unable to transform value for property path "value": Expected a Boolean.
2
Lookup data transformers. - mr12086

2 Answers

6
votes

Entity.php

public function getValue()
{
    return (boolean)$this->value;
}
0
votes

this worked for me:

rewrite the function in the Entity, adding explicitly boolean values in returns

public function getEstado() {
    if ($this->estado===1) {
        return TRUE;
    }
    return FALSE;
}