jQuery 1.5.1 with autocomplete 1.1
Hello,
we've been using jQuery 1.2.6 with autocomplete 1.1pre for some time now and it has been working ok, but after we upgraded jQuery from 1.2.6 to 1.5.1 the autocomplete stopped working.
I think it's best if I just paste the code:
- $().ready(function () {
$("#<%=txt_proizvajalec.ClientID%>").autocomplete('autocomplete/SearchCategory.ashx', {
dataType: 'json',
minChars: 0,
extraParams: { type: function () { return "1"; } },
width: 500,
cacheLength: 20,
matchContains: true,
autoFill: false,
scrollHeight: 300,
scroll: true,
max: 25,
parse: function (data) {
var parsed = [];
data = data.text;
for (var i = 0; i < data.length; i++) {
parsed[parsed.length] = {
data: data[i],
id: data[i].id,
name: data[i].name,
result: data[i].name,
value: data[i].name
};
}
return parsed;
},
formatItem: function (row) {
return row.name;
},
formatMatch: function (row) {
return row.name;
},
formatResult: function (row) {
return row.name;
}
});
$("#<%=txt_proizvajalec.ClientID%>").result(function (event, data, formatted) {
if (data) {
$("#lbl_proizvajalec").val(data["id"]);
$("#<%=txt_proizvajalec.ClientID%>").val(data["name"]);
$("#<%=txt_proizvajalec.ClientID%>").flushCache();
}
else {
$("#lbl_proizvajalec").val("");
}
});
$("#<%=txt_proizvajalec.ClientID%>").blur(function () {
$("#<%=txt_proizvajalec.ClientID%>").search(); //trigger result() on blur, even if autocomplete wasn't used
});
$('#<%=txt_proizvajalec.ClientID%>').focus(function () {
$('#<%=txt_proizvajalec.ClientID%>').trigger("click"); //or "click", at least one should work
});
$("#<%=txt_model.ClientID%>").autocomplete('autocomplete/SearchCategory.ashx', {
dataType: 'json',
minChars: 0,
extraParams: { type: function () { return "2"; }, pcat: function () { return document.getElementById('lbl_proizvajalec').value; } },
width: 500,
cacheLength: 20,
matchContains: true,
autoFill: false,
scrollHeight: 300,
scroll: true,
max: 25,
parse: function (data) {
var parsed = [];
data = data.text;
for (var i = 0; i < data.length; i++) {
parsed[parsed.length] = {
data: data[i],
id: data[i].id,
name: data[i].name,
result: data[i].name,
value: data[i].name
};
}
return parsed;
},
formatItem: function (row, i, max) {
return row.name;
},
formatMatch: function (row, i, max) {
return row.name;
},
formatResult: function (row) {
return row.name;
}
});
$("#<%=txt_model.ClientID%>").result(function (event, data, formatted) {
if (data) {
$("#lbl_model").val(data["id"]);
$("#<%=txt_model.ClientID%>").val(data["name"]);
$("#<%=txt_model.ClientID%>").flushCache();
}
else {
$("#lbl_model").val("");
}
});
$("#<%=txt_model.ClientID%>").blur(function () {
$("#<%=txt_model.ClientID%>").search(); //trigger result() on blur, even if autocomplete wasn't used
});
$('#<%=txt_model.ClientID%>').focus(function () {
$('#<%=txt_model.ClientID%>').trigger("click"); //or "click", at least one should work
});
$("#<%=txt_tip.ClientID%>").autocomplete('autocomplete/SearchCategory.ashx', {
dataType: 'json',
minChars: 0,
extraParams: { type: function () { return "2"; }, pcat: function () { return document.getElementById('lbl_model').value; } },
width: 500,
cacheLength: 20,
matchContains: true,
autoFill: false,
scrollHeight: 300,
scroll: true,
max: 25,
parse: function (data) {
var parsed = [];
data = data.text;
for (var i = 0; i < data.length; i++) {
parsed[parsed.length] = {
data: data[i],
id: data[i].id,
name: data[i].name,
result: data[i].name,
value: data[i].name
};
}
return parsed;
},
formatItem: function (row, i, max) {
return row.name;
},
formatMatch: function (row, i, max) {
return row.name;
},
formatResult: function (row) {
return row.name;
}
});
$("#<%=txt_tip.ClientID%>").result(function (event, data, formatted) {
if (data) {
$("#lbl_tip").val(data["id"]);
$("#<%=txt_tip.ClientID%>").val(data["name"]);
$("#<%=txt_tip.ClientID%>").flushCache();
}
else {
$("#lbl_tip").val("");
}
});
$("#<%=txt_tip.ClientID%>").blur(function () {
$("#<%=txt_tip.ClientID%>").search(); //trigger result() on blur, even if autocomplete wasn't used
});
$('#<%=txt_tip.ClientID%>').focus(function () {
$('#<%=txt_tip.ClientID%>').trigger("click"); //or "click", at least one should work
});
});
The SearchCategory.ashx writes a response with the data in this format:
{text:[{id:"816",name:"AUDI"},{id:"8230",name:"RENAULT"}]}
But the "ac_results" isn't appended to the page like it was before with 1.2.6. I have no idea how to fix it, but I have tried alot of code which I found either here or on google, none of them seem to work. The thing is I need to pass the "name" string to the textbox and/or "ac_results" and the "id" string back to a hidden field. Any help would be appreciated.
Best regards,
Thomas