mardi 28 février 2017

Symfony CheckboxType could not be unchecked

Here are the existing codes:

Form type as :

->add('isProcessor', CheckboxType::class,array('label' => 'As Processor', 'required'=>false))

Entity as:

/**
 * @var boolean $isProcessor
 *
 * @ORM\Column(name="is_processor", type="boolean")
 * @Assert\NotBlank()
 */
private $isProcessor;

page as : enter image description here

How could I make this happen:

  • if the checkbox is checked, isProcessor should be true
  • if the checkbox is unchecked, isProcessor should be false

I am not if there should be some other parameters with CheckboxType when building the form. Or I need add some other codes to convert the values.

Also the field could not be modified in modify page. Is there any way to make the checkbox element disable in modify page but enable in create page?

Thank you very much for your help.




Aucun commentaire:

Enregistrer un commentaire