Created
March 4, 2016 20:41
-
-
Save szbl/b8476c32eeeaeea218ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$( 'select.multiline' ).each(function($){ | |
var ajax_url = false, minInputLength = 3; | |
if ( $( this ).data( 'min-input' ) ) | |
{ | |
minInputLength = $( this ).data( 'min-input' ); | |
} | |
ajax_url = $( this ).data( 'source' ); ?> | |
if ( !ajax_url ) return false; | |
$( this ).select2({ | |
ajax: { | |
url: ajax_url, | |
dataType: 'json', | |
delay: 250, | |
data: function (params) { | |
return { | |
q: params.term, // search term | |
page: params.page | |
}; | |
}, | |
processResults: function (data, params) { | |
params.page = params.page || 1; | |
var selectResultsData = $.map(data.items, function (obj) { | |
obj.id = obj.value; | |
obj.text = obj.label; | |
return obj; | |
}); | |
return { | |
results: selectResultsData, | |
pagination: { | |
more: (params.page * 30) < data.total_count | |
} | |
}; | |
}, | |
cache: true | |
}, | |
escapeMarkup: function (markup) { return markup; }, | |
minimumInputLength: minInputLength, | |
templateResult: formatContactInfoResults, | |
templateSelection: formatContactInfoResultsSelection | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment