I have two Text filter web parts (Project and Customer Name) with Apply Filters button for one list. There is a SPServices.SPAutocomplete
on each and it works great. Now, I want to show the values in the second filter's autocomplete based on selected value of the first one so I'm using a dynamic CAMLQuery
.
The problem is that it simply is not working. I tried it with the static CAMLQuery
value and it works. Based on other people's questions here on Stack, and tons of other examples, I saw it can be done dynamically. I suspect the problem hides in the time of call of the autocomplete, but I don't have that much JS / Jquery background. Does it load on document.ready
only and ignores all the variables after?
Here is my snippet, it is inside the $(document).ready(function() {}
as well as other code. Any help is much appreciated.
var projectName;
var camlQuery;
document.getElementById('Customer_Name_Filter_Id').onclick = function(){
projectName = document.getElementById('Project_Name_Filter_Id').value;
camlQuery = "<Eq><FieldRef Name='Title'/><Value Type='Text'>"+projectName+"</Value></Eq>";
};
$().SPServices.SPAutocomplete({
sourceList: "{7DEBDF67-3DBE-4D57-BD09-E9CE7B60A09E}",
sourceColumn: "Customer",
columnName: "CustomerNameFilter",
CAMLQuery: camlQuery,
filterType: "Contains",
highlightClass: "ms-bold",
uniqueVals: true,
ignoreCase: true,
numChars: 3,
slideDownSpeed: "fast",
debug: true
});
EDIT:
I tried to put the $().SPServices.SPAutocomplete
inside the .onclick
function, and a couple of other JS events and after this, the filter WP just froze and could not be typed in.