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,
        ))
    }
}
2
  • fixed grammatical and improve the block code format Commented Apr 22, 2016 at 5: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) Commented Apr 22, 2016 at 5:54

1 Answer 1

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();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.