WARNING: You are browsing the documentation for version 2.x which is not maintained anymore. If some of your projects are still using this version, consider upgrading.

7. Select2

2.x version
Unmaintained
2.x

7. Select2

The admin comes with select2 integration since version 2.2.6. Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.

The select2 is enabled on all select form elements by default.

7.1. Disable select2

If you don’t want to use select2 in your admin, you can disable it in config.yml.

  • YAML
    1
    2
    3
    sonata_admin:
        options:
            use_select2:    false # disable select2
    

Note

If you disable select2, autocomplete form types will stop working.

7.2. Disable select2 on some form elements

To disable select2 on some select form element, set data attribute data-sonata-select2="false" to this form element.

1
2
3
4
5
->add('category', 'sonata_type_model',
    array(
        'attr'=>array('data-sonata-select2'=>'false')
    )
)

7.3. AllowClear

Select2 parameter allowClear is handled automatically by admin. But if you want to overload the default functionality, you can set data attribute data-sonata-select2-allow-clear="true" to enable allowClear or data-sonata-select2-allow-clear="false" to disable the allowClear parameter.

1
2
3
4
5
->add('category', 'sonata_type_model',
    array(
        'attr'=>array('data-sonata-select2-allow-clear'=>'false')
    )
)

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.