0

I need a select All check box with this multiple check boxes. If I click that select all check box, all the check boxes should be selected and deselect also I need.

class HabitacionFotoPrincipalType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options) {
        $builder->add('choice', 'choice', array(
            'choices'   => array(
                'morning'   => 'Morning',
                'afternoon' => 'Afternoon',
                'evening'   => 'Evening',
            ),
            'expanded' => true,
            'multiple'  => true,
        ))
    }
}
Robert
  • 10,403
  • 14
  • 67
  • 117
Ashok
  • 1
  • 1
  • fixed grammatical and improve the block code format – Robert Apr 22 '16 at 05:42
  • presuming that you don't need to actually store the information whether the user has clicked the select all box, this is easy to do with an additional checkbox + javascript/jquery directly in the view (i.e. no need to modify the actual form type class for this) – ejuhjav Apr 22 '16 at 05:54

1 Answers1

1

The 'select all' checkbox is not something Symfony supports by default. So basically this would require you to add an additional checkbox, and to add Javascript logic to that.

$builder->add('selectAll', CheckboxType::class, array(
    'attr' => array('class'=>'selectAllCheckboxes')
);

And the Javascript to select all others:

$('.selectAllCheckboxes').click(function(){
    $('<class for other checkboxes>').click();
});
Rvanlaak
  • 2,971
  • 20
  • 40