Нема описа
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.

select2-all.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. $(document).ready(function(){
  2. //stert of select2
  3. $('.global-select2').each(function(){
  4. var urlglobal = base_url + '/fetch/globalfetch';
  5. var id = $(this).attr('id'); // ID dari element yang di definisikan sebagai select 2
  6. var link = $(this).attr('link') == 'globalfetch' ? urlglobal : $(this).attr('link'); // link yang ditembak untuk diambil oleh select 2
  7. var t = $(this).attr('t'); // t = table(penyamaran) ,hanya jika menggunakan global link
  8. var s = $(this).attr('s'); // s = select(penyamaran) ,hanya jika menggunakan global link
  9. var placeholder = $(this).attr('placeholder') != '' ? $(this).attr('placeholder') : 'choose the option'; // placeholder
  10. var allowclear = $(this).attr('required') ? false : true; // untuk menentukan dia boleh di clear atau tidak
  11. var tag = $(this).attr('tags') == true ? true : false;
  12. var maxselect = (typeof $(this).attr('maxs') !== "undefined") ? (($(this).attr('maxs') != '') ? $(this).attr('maxs') : 1000) : 1000; //untuk memberi rule , maksimal value yg di select hanya sejumlah berapa
  13. var exception = (typeof $(this).attr('exception') !== "undefined") ? $(this).attr('exception') : '';
  14. var onlyin = (typeof $(this).attr('onlyin') !== "undefined") ? $(this).attr('onlyin') : '';
  15. var w = new Array();
  16. var exceptid = exception != '' ? getvaluefrom(exception) : '';
  17. var onlyinid = onlyin != '' ? getvaluefrom(onlyin) : '';
  18. var indextones = 'select-index-1';
  19. if (typeof link === "undefined") {
  20. link = '#';
  21. }
  22. if (typeof placeholder === "undefined") {
  23. placeholder = 'choose the option';
  24. }
  25. if (typeof s === "undefined") {
  26. w = [];
  27. } else {
  28. if (s != '' && typeof s.split(',')[1] === 'undefined') {
  29. indextones = 'select-index-1';
  30. }else{
  31. indextones = s.split(',')[1];
  32. }
  33. var w = [
  34. {field:indextones , operator:'LIKE' , value:'-NMSearch-'} //NMSearch untuk di replace dengan keyword
  35. ];
  36. }
  37. var parameters = {
  38. 'q': '',
  39. 't': t,
  40. 's': s,
  41. 'w': w,
  42. };
  43. // if (destroy == true) {
  44. // $('#'+id).select2('destroy');
  45. // }else{
  46. if (link != '#') {
  47. $('#' + id).select2({
  48. tokenSeparators: [','],
  49. allowClear: allowclear,
  50. theme: 'bootstrap4',
  51. placeholder: placeholder,
  52. maximumSelectionLength: maxselect,
  53. ajax: {
  54. url: link,
  55. dataType: 'json',
  56. type: 'post',
  57. data: function(params) {
  58. if (exception != '') {
  59. // $('#'+id).on('select2:opening',function(e){
  60. exceptid = getvaluefrom(exception);
  61. // })
  62. }
  63. if (onlyin != '') {
  64. // $('#'+id).on('select2:opening',function(e){
  65. onlyinid = getvaluefrom(onlyin);
  66. // })
  67. }
  68. return {
  69. "_token": $('meta[name="csrf-token"]').attr('content'),
  70. q: params.term, // search term
  71. page: params.page,
  72. parameter: parameters,
  73. except: exceptid,
  74. onlyin: onlyinid,
  75. };
  76. },
  77. processResults: function(data, params) {
  78. return {
  79. results: data.item
  80. }
  81. },
  82. cache: true
  83. },
  84. tags: tag,
  85. tokeSparator: [','],
  86. escapeMarkup: function(markup) { return markup; }, // let our custom formatter work
  87. minimumInputLength: 0,
  88. templateResult: formatResult, // omitted for brevity, see the source of this page
  89. templateSelection: formatResult // omitted for brevity, see the source of this page
  90. });
  91. } else {
  92. $('#' + id).select2({
  93. allowClear: allowclear,
  94. theme: 'bootstrap4',
  95. placeholder: placeholder,
  96. });
  97. }
  98. // }
  99. });
  100. function formatResult(result) {
  101. return result.text;
  102. }
  103. //end of select2
  104. });