0

I am using symfony2

I have Manytomany entity and using multiple select box like this.

in php

    ->add('availLangs','entity',array(
            'class' => 'UserBundle:Lang',
            'label' => 'form.availLangs',
            'multiple' => true))

in twig

{{ form_widget(form.availLangs) }}

enter image description here

It's nicely simple though,however when there are many choices(like 10~), the situation could be chaos for user.

So I am trying to implement choose box like this

HTML multiple select box

or

Some widget to select multiple items from many items easily.

Is there good reference for implement with symfony2 or formbuilder?

Community
  • 1
  • 1
whitebear
  • 11,200
  • 24
  • 114
  • 237

1 Answers1

4

You could use select2 jquery widget , it has a nice search input where you can type some characters of the desired option and the widget will get them to you. https://select2.github.io/

Sample : http://jsfiddle.net/eoaa2wqw/

In symfony2 , just add select2 class to your input through builder or twig

->add('availLangs','entity',array(
            'class' => 'UserBundle:Lang',
            'label' => 'form.availLangs',
            'attr'=> array('class'=> 'select2') <-- here 
            'multiple' => true))

then acitivate select2 with :

$('.select2').select2(// options maybe ) ; 
zizoujab
  • 7,603
  • 8
  • 41
  • 72