I have a class Measure with a boolean property named "isShared"
/**
* @ORM\Entity(repositoryClass="App\Repository\MeasureRepository")
* @UniqueEntity("name", message = "This value is already used")
*/
class Measure
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(name="is_shared", type="boolean")
*/
private $isShared;
}
And a form in which the value of the value of the isShared property should be changed through a checkbox.
class MeasureType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('isShared', CheckboxType::class, array(
'required' => false,
'label' => 'Shared',
'attr' => array(
'data-on-color' => 'primary',
'data-off-color' => 'default'
)
));
}
The problem is that the rendered html is always
<input type="checkbox" id="measure_isShared" name="measure[isShared]" data-on-color="primary" data-off-color="default" value="1" /> Shared</label>
not taking into account the value of the property in the object. When I pass to the form a Measure object with the property isShared set to false, the value of the input is always 1.
What I'm doing wrong? Thank you!
Aucun commentaire:
Enregistrer un commentaire