Good afternoon all! Thanks so much for looking. I've got a JavaScript issue here that I'm not sure where I'm going wrong. Here's the scenario:
I have a SP Form with several custom fields that need to have an auto-complete function applied to them. There is a REST call that populates the auto-complete, that part works great. The issue, however, lies with attempting to assign the field TITLE to a variable. Here's what I've got so far:
$(function() {
$("input[title='FIELD1']").autocomplete({
source: function( request, response ) {
var term = request.term;
var restUrl = PWATABLEURL
XXX.PO.Data.loadJSON(restUrl, function (data) {
var items = [];
var entries = data.value;
while (entries.length > 0) {
var entry = entries.shift();
var item = { value: entry.ResourceName, label: entry.ResourceName};
items.push(item);
}
response(items);
});
},
minLength: 3
});
$("input[title='FIELD1']").attr("title", "Enter 3 characters to search");
$(".ui-autocomplete-input").on("autocompletechange", function(e, u){
$(this).focus();
$(this).change();
});
});
In this example, I've explicitly defined 'FIELD1' as the field to apply the function to and all is well. But when i substitute:
let varField = 'FIELD1'
console.log(varField);
$("input[title=varField]").autocomplete.....
it fails with no real help from the console messages--it just doesnt work. The plan was to set up a case switch where it would work like,
If Field title = FIELD1, set varField to 'FIELD1' If Field title = FIELD2, set varField to 'FIELD2' etc..
In this way each field we needed to apply the auto-complete function to would get the same block of code without using repeating sections in the script.
I'm still plugging away, but i feel like I'm missing something easy here as i can't even get to a single variable, much less multiple. Any and all input is appreciated and as always, thanks to the community for taking the time.