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.
In the first case, I am selecting all the possible groups from DB as JSON object and set it to request and get it from request on my JSP file.
There I am doing the following operations....
var availableGrps = $("#mainGrpList").val();
availableGrps = availableGrps.replace(/\047/gi, "\"");
availableGrps = availableGrps.replace(/\\/gi,"");
availableGrps = availableGrps.replace(/\'/g,"/\"");
var aGrps = JSON.parse(availableGrps);
mainGrpList is a hidden type in my JSP
Why I am doing like this is, I am not getting the full string from hidden variable. So, I converted the double cords to single and set it in the hidden variable and taking it in the JQuery.
Then I am replacing all the single cords to double and convert it to JSON array.
$("#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.