Teshan N.
Teshan N.

Reputation: 2545

Symfony forms checkbox dropdown

I am working on a Symfony form where it must have a dropdown with checkboxes to select multiple values. However choice and entity input types have 'multiple' and 'expanded' attributes which cannot produce what I need. Shown below is my requirement.

enter image description here

Here's how my form is:

$form = $this->createFormBuilder()
    ->add('features', 'choice', array('choices'=>array('a','b','c'), 'multiple'=> true))
    ->getForm();

Above code produces an expanded dropdown with a multi select.

Upvotes: 0

Views: 1301

Answers (2)

loic
loic

Reputation: 36

you have to use a JS library like https://github.com/ehynds/jquery-ui-multiselect-widget.

You can find the answer here : How to use Checkbox inside Select Option

Upvotes: 1

shuba.ivan
shuba.ivan

Reputation: 4071

for creating check box with opportunity check one box, you can use this

        $builder
        ->add('check_box', ChoiceType::class, [
            'label' => 'status',
            'multiple' => false,
            'expanded' => false,
            'choices' => [a, b, c],
            'translation_domain' => 'common',
            'label_attr' => ['class' => 'cursor_text'],
            'attr' => [
                'style' => 'some style'
            ]
        ]);

Upvotes: 0

Related Questions