I'm pretty new to java script and I was using the autocomplete library from Awesomplete and had used it for multiple values, where auto complete for the words will be shown when separated by comma, which is working fine.
Working auto complete for comma delimited multiple words
Script
function f(){
alert("called");
var input = document.getElementById("myinput");
new Awesomplete(input, {
filter: function(text, input) {
return Awesomplete.FILTER_CONTAINS(text, input.match(/[^,]*$/)[0]);
},
item: function(text, input) {
return Awesomplete.ITEM(text, input.match(/[^,]*$/)[0]);
},
replace: function(text) {
var before = this.input.value.match(/^.+,\s*|/)[0];
this.input.value = before + text + " , ";
}
});
}
Now, what I want is to do the same when I use words with space, it has to suggest auto complete for words when separated by spaces. For example: I need to achieve auto completion to " My Name Is John" instead of "My,Name,Is,John".
I tried with
function f(){
alert("called");
var input = document.getElementById("myinput");
new Awesomplete(input, {
filter: function(text, input) {
return Awesomplete.FILTER_CONTAINS(text, input.match(/[^,]*$/)[0]);
},
item: function(text, input) {
return Awesomplete.ITEM(text, input.match(/[^,]*$/)[0]);
},
replace: function(text) {
var before = this.input.value.match(/^.+,\s*|/)[0];
this.input.value = before + text + " "; //tried using space as delimiter
}
});
}
But it is showing autocomplete only for first word, so how can I get this working?
You could replace the comma in your regex patterns to spaces. Try the following