comma separated auto complete with jquery not working with javascript json data -
i trying create comma separated auto complete text field auto complete json data comes java script itself.. see code below:
the java script array:
var remark = [ "is under construction", "is part of construction.", "has acquired other work.", "could not source construction." ];
the auto complete method:
$("#remark").bind("keydown", function(event) { if (event.keycode === $.ui.keycode.tab && $(this).data("ui-autocomplete").menu.active) { event.preventdefault(); } }).autocomplete({ source: function(request, response) { $.getjson(json.stringify(remark), { //this line issue.. term: extractlast(request.term) }, response); }, search: function() { var term = extractlast(this.value); if (term.length < 2) { return false; } }, focus: function() { return false; }, select: function(event, ui) { var terms = split(this.value); terms.pop(); terms.push(ui.item.value); terms.push(""); this.value = terms.join(","); return false; } });
the helper functions:
function split(val) { return val.split(/,\s*/); } function extractlast(term) { return split(term).pop(); }
the var remark
holds the data auto complete show users...
the $.getjson(json.stringify(remark)
fetching data auto complete..functionality not working aspect ed.. while works when use fetch data mysql server.. when using java script array not working..
any or suggestion great help.. in advance...
the source property directly accepts array data source. can directly pass local array source property:
var remark = [ "is under construction", "is part of construction.", "has acquired other work.", "could not source construction."]; $("#remark").bind("keydown", function (event) { if (event.keycode === $.ui.keycode.tab && $(this).data("ui-autocomplete").menu.active) { event.preventdefault(); } }).autocomplete({ source: remark, search: function () { var term = extractlast(this.value); if (term.length < 2) { return false; } }, focus: function () { return false; }, select: function (event, ui) { var terms = split(this.value); terms.pop(); terms.push(ui.item.value); terms.push(""); this.value = terms.join(","); return false; } }); function split(val) { return val.split(/,\s*/); } function extractlast(term) { return split(term).pop(); }
Comments
Post a Comment