123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- $(document).ready(function(){
-
- $('.global-select2').each(function(){
- var urlglobal = base_url + '/fetch/globalfetch';
- var id = $(this).attr('id');
- var link = $(this).attr('link') == 'globalfetch' ? urlglobal : $(this).attr('link');
- var t = $(this).attr('t');
- var s = $(this).attr('s');
- var placeholder = $(this).attr('placeholder') != '' ? $(this).attr('placeholder') : 'choose the option';
- var allowclear = $(this).attr('required') ? false : true;
- var tag = $(this).attr('tags') == true ? true : false;
- var maxselect = (typeof $(this).attr('maxs') !== "undefined") ? (($(this).attr('maxs') != '') ? $(this).attr('maxs') : 1000) : 1000;
- var exception = (typeof $(this).attr('exception') !== "undefined") ? $(this).attr('exception') : '';
- var onlyin = (typeof $(this).attr('onlyin') !== "undefined") ? $(this).attr('onlyin') : '';
- var w = new Array();
- var exceptid = exception != '' ? getvaluefrom(exception) : '';
- var onlyinid = onlyin != '' ? getvaluefrom(onlyin) : '';
- var indextones = 'select-index-1';
-
- if (typeof link === "undefined") {
- link = '#';
- }
-
- if (typeof placeholder === "undefined") {
- placeholder = 'choose the option';
- }
-
- if (typeof s === "undefined") {
- w = [];
- } else {
- if (s != '' && typeof s.split(',')[1] === 'undefined') {
- indextones = 'select-index-1';
- }else{
- indextones = s.split(',')[1];
- }
- var w = [
- {field:indextones , operator:'LIKE' , value:'-NMSearch-'}
- ];
- }
- var parameters = {
- 'q': '',
- 't': t,
- 's': s,
- 'w': w,
- };
-
-
-
- if (link != '#') {
- $('#' + id).select2({
- tokenSeparators: [','],
- allowClear: allowclear,
- theme: 'bootstrap4',
- placeholder: placeholder,
- maximumSelectionLength: maxselect,
- ajax: {
- url: link,
- dataType: 'json',
- type: 'post',
- data: function(params) {
- if (exception != '') {
-
- exceptid = getvaluefrom(exception);
-
- }
- if (onlyin != '') {
-
- onlyinid = getvaluefrom(onlyin);
-
- }
- return {
- "_token": $('meta[name="csrf-token"]').attr('content'),
- q: params.term,
- page: params.page,
- parameter: parameters,
- except: exceptid,
- onlyin: onlyinid,
- };
- },
- processResults: function(data, params) {
- return {
- results: data.item
- }
- },
- cache: true
- },
- tags: tag,
- tokeSparator: [','],
- escapeMarkup: function(markup) { return markup; },
- minimumInputLength: 0,
- templateResult: formatResult,
- templateSelection: formatResult
- });
- } else {
- $('#' + id).select2({
- allowClear: allowclear,
- theme: 'bootstrap4',
- placeholder: placeholder,
- });
- }
-
- });
-
- function formatResult(result) {
- return result.text;
- }
-
-
- });
|