Tip: Click lines to highlight, hold ctrl/cmd to multi-select
JQuery Autocomplete (parse method) JSON Object (1-Feb @ 15:20)
Syntax Highlighted Code
- <script>
- $(function() {
- $.ajaxSetup ({ cache: false });
- var ajaxLoadingImg = '<img
- src='${Url.Content("/content")}/img/ui/icons/spinner1.gif' />';
- $("#select1").attr("disabled", "disabled");
- //Multiple select option cloning
- $('#add').click(function() {
- return !$('#select1 option:selected').remove().appendTo('#select2');
- });
- $('#remove').click(function() {
- return !$('#select2 option:selected').remove().appendTo('#select1');
- });
- //Autocomplete
- $("#instrument").autocomplete("/RegulatorSet/InstrumentSearchAutocomplete", {
- delay: 150, // millisecond delay after keyup/down event
- minChars: 2, // min no of chars to activate
- mustMatch: false,
- max: 100, // max no of items
- dataType: 'json',
- parse: function(json) {
- var resultList = new Array();
- $("#instrument").after('<span class="ajax-load">' + ajaxLoadingImg
- + 'Loading Insrument Group' + '</span>');
- var optionsHtml = '';
- for(var i=0; i<json.length; i++){
- optionsHtml += '<option value="' + json[i].optionValue + '">' +
- json[i].optionDisplay + '</option>';
- }
- $("#select1").removeAttr("disabled");
- $("span.ajax-load").remove();
- $("#select1").html(optionsHtml);
- return resultList;
- },
- formatItem: function(resultList){
- // No ul required
- }
- });
- });
- </script>
Plain Code
<script>
$(function() {
$.ajaxSetup ({ cache: false });
var ajaxLoadingImg = '<img
src='${Url.Content("/content")}/img/ui/icons/spinner1.gif' />';
$("#select1").attr("disabled", "disabled");
//Multiple select option cloning
$('#add').click(function() {
return !$('#select1 option:selected').remove().appendTo('#select2');
});
$('#remove').click(function() {
return !$('#select2 option:selected').remove().appendTo('#select1');
});
//Autocomplete
$("#instrument").autocomplete("/RegulatorSet/InstrumentSearchAutocomplete", {
delay: 150, // millisecond delay after keyup/down event
minChars: 2, // min no of chars to activate
mustMatch: false,
max: 100, // max no of items
dataType: 'json',
parse: function(json) {
var resultList = new Array();
$("#instrument").after('<span class="ajax-load">' + ajaxLoadingImg
+ 'Loading Insrument Group' + '</span>');
var optionsHtml = '';
for(var i=0; i<json.length; i++){
optionsHtml += '<option value="' + json[i].optionValue + '">' +
json[i].optionDisplay + '</option>';
}
$("#select1").removeAttr("disabled");
$("span.ajax-load").remove();
$("#select1").html(optionsHtml);
return resultList;
},
formatItem: function(resultList){
// No ul required
}
});
});
</script>