You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6KB

  1. /* Tooltip */
  2. $('[data-toggle="tooltip"]').tooltip();
  3. /* Select2 */
  4. if ($('.select2, select.form-control').length) {
  5. $('form .form-widget>select.form-control, .select2').each(function (i, elm) {
  6. if (!$(this).hasClass('disable-select2')) {
  7. setSelect2($(elm));
  8. }
  9. });
  10. $('form .form-inline>select.form-control').each(function (i, elm) {
  11. if (!$(this).hasClass('disable-select2')) {
  12. setSelect2($(elm));
  13. }
  14. });
  15. }
  16. function setSelect2($select) {
  17. if (typeof $select.data('select2-id') === 'undefined') {
  18. $select.data('init', 'set')
  19. var options = {
  20. width: "100%",
  21. theme: "bootstrap4",
  22. dropdownAutoWidth: false,
  23. allowClear: true,
  24. minimumResultsForSearch: 8
  25. };
  26. if ($select.data('allow-clear') == 'false') {
  27. options.allowClear = false;
  28. }
  29. if ($select.data('width')) {
  30. options.width = 'auto'
  31. }
  32. if ($select.find('option[value=""]')) {
  33. options.placeholder = $select.find('option[value=""]').html()
  34. }
  35. /*if($select.is(':required') == false) {
  36. options.allowclear = true
  37. }*/
  38. var myselect = $select.select2(options);
  39. myselect.on('select2:select', function (e) {
  40. var event = new Event('change');
  41. e.target.dispatchEvent(event);
  42. });
  43. myselect.on('select2:unselect', function (e) {
  44. var event = new Event('change');
  45. e.target.dispatchEvent(event);
  46. });
  47. return myselect;
  48. }
  49. }