Hi,
I'm trying to call a javascript function to format the string that appears in the autocomplete list and textbox. I've tried in success() method and in _renderItem as well. But it just doesn't call the method:
- $(function () {
$('#<%= txtAutoComplete.ClientID %>').autocomplete({
source: function (request, response) {
$.ajax({
url: "AutoCompleteWS.asmx/GetStationDataJSON",
type: "POST",
data: "{'input': '" + request.term + "', 'limit': '10', 'maxAlternateTerms' : '3', 'formatString' : '{DataTextField}{DataCodeField: - [_F]}{DataAlternateField: - [*F2]}'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, textStatus, jqXHR) {
response($.map(data.d, function (item) {
return {
searchTerm: request.term,
data: item,
label: formatString("MY FORMAT", item.DisplayText), // the options list display text
value: formatString("MY FORMAT", item.SelectedText) // what will be display in the textbox
}
}));
},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 1,
select: function (event, ui) {
// label actually contains the value so save selected value into hidden field
$('#<%= hdnAutoComplete.ClientID %>').val(ui.item.data.Value);
// do postback
<%= Page.ClientScript.GetPostBackEventReference(this, "newevent") %>;
}
}).data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a title='" + item.data.ToolTip + "'>" + formatString("MY FORMAT", item.data.DisplayText) + "</a>")
.appendTo(ul);
};
});
Any suggestions? Can this be done? The javascript function is in another javascript file but I've tried to move the javascript code in $(function () { as well.
Thanks in advance.
Sidharth