Reputation: 2729
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.
Upvotes: 2
Views: 4568
Reputation: 101
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;
}
Upvotes: 0
Reputation: 196
Entity.php
public function getValue()
{
return (boolean)$this->value;
}
Upvotes: 6