Description
My use case is probably an edge case - I have multiple instances of the autocomplete on a page. They are looking at the same data set, but are individual fields for parts of the data (e.g. name, email). In the autocomplete options, I want to show the concatenated results, but on selection fill the fields with parts of the data, not the entire string.
I accomplished this pretty okay with adding an inputValue
callback:
function inputFcn(selected) {
if (selected) {
var results = selected.split('-');
if (results.length > 1) {
document.getElementById('email-auto').value = results[1].trim();
}
selected = results[0].trim();
}
return selected;
};
But if input#email-auto
is also an autocomplete, when I set the value it pops the options menu open with the only matching entry. I want to avoid this if possible, and I'm not sure if there is a way to accomplish this.
Please let me know if this is simply a bad practice as well - I'm trying to create a proof of concept that follows a particular requested set of guidelines right now, and if this is not something I should be doing I can take that back to the requestors and work out a better solution with them.