recipe_select2.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. Select2
  2. =======
  3. The admin comes with `select2 <http://ivaynberg.github.io/select2/>`_ integration
  4. since version 2.2.6. Select2 is a jQuery based replacement for select boxes.
  5. It supports searching, remote data sets, and infinite scrolling of results.
  6. The select2 is enabled on all ``select`` form elements by default.
  7. Disable select2
  8. ---------------
  9. If you don't want to use select2 in your admin, you can disable it in ``config.yml``.
  10. .. configuration-block::
  11. .. code-block:: yaml
  12. # app/config/config.yml
  13. sonata_admin:
  14. options:
  15. use_select2: false # disable select2
  16. .. note::
  17. If you disable select2, autocomplete form types will stop working.
  18. Disable select2 on some form elements
  19. -------------------------------------
  20. To disable select2 on some ``select`` form element, set data attribute ``data-sonata-select2 = "false"`` to this form element.
  21. .. code-block:: php
  22. public function configureFormFields(FormMapper $formMapper)
  23. {
  24. $formMaper
  25. ->add('category', 'sonata_type_model', array(
  26. 'attr' => array(
  27. 'data-sonata-select2' => 'false'
  28. )
  29. ))
  30. ;
  31. }
  32. .. note::
  33. You have to use false as string! ``"false"``!
  34. AllowClear
  35. ----------
  36. Select2 parameter ``allowClear`` is handled automatically by admin. But if you want
  37. to overload the default functionality, you can set data attribute ``data-sonata-select2-allow-clear="true"``
  38. to enable ``allowClear`` or ``data-sonata-select2-allow-clear = "false"`` to disable the ``allowClear`` parameter.
  39. .. code-block:: php
  40. public function configureFormFields(FormMapper $formMapper)
  41. {
  42. $formMapper
  43. ->add('category', 'sonata_type_model', array(
  44. 'attr' => array(
  45. 'data-sonata-select2-allow-clear' => 'false'
  46. )
  47. ))
  48. ;
  49. }
  50. .. note::
  51. You have to use false as string! ``"false"``!