Hi,
I have an issue with my autocomplete UI.
In my application, I have two text boxes and I want to select values using autocomplete. I want to display the autocomplete details based on the data selected on the previous value. and in that field also, I am using autocomplete.
$("#grpCodeLbl").autocomplete({
source: aGrps,
select: function(event, ui) {
event.preventDefault();
var grpCd = ui.item.value;
$("#grpCodeLbl").val(ui.item.label);
$('#GroupCode').val(ui.item.value);
$("#mainDesigLabel").attr('disabled', false);
populateMainDesigs();
//return false;
},
change: function(event, ui){
$('#mainDesigLabel').val("");
$('#MainDesigCode').val("");
}
});
This is the method used to display autocomplete details on the first text box. In this, I wrote one custom method to take values from DB and set it as a string using AJAX to avoid DB fetching each time.
populateMainDesigs() is that method.
var retMainGrps;
function populateMainDesigs(){
$.ajax({
url: "empReqCreateNewReq.do",
data : { grpChange: true, GroupCode : $('#GroupCode').val(), ajaxCall : true },
dataType : 'json',
success: function(json) {
retMainGrps = json;
//retJson = JSON.parse(json)
alert("=== DATA ==== "+json);
//rePopulateDesigDropdown(json);
},
error : function(xhr, status) {
alert('Sorry, there was a problem while placing your ajax request. Contact Admin!');
}
});
}
I want the result of this method as the source of the next autocomplete text box.
$("#mainDesigLabel").autocomplete({
source: retMainGrps
});
While alerting, i am getting correct values but autocomplete function is not working for this text box.
It says "TypeError: this.source is not a function
Source"
Please help me to find a solution for this problem.