2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 03:29:00 +00:00

validate function for autocomplete

This commit is contained in:
Faris Ansari 2018-04-02 22:37:22 +05:30
parent 7eeb3ca137
commit a74ec62abe

View File

@ -8,18 +8,26 @@ class AutocompleteControl extends BaseControl {
this.setupAwesomplete();
}
setupAwesomplete() {
async setupAwesomplete() {
this.awesomplete = new Awesomplete(this.input, {
minChars: 0,
maxItems: 99
});
this.list = await this.getList();
// rebuild the list on input
this.input.addEventListener('input', async (event) => {
let list = await this.getList();
this.awesomplete.list = list;
this.input.addEventListener('input', (event) => {
this.awesomplete.list = this.list;
});
}
validate(value) {
if (this.list.includes(value)) {
return value;
}
return false;
}
};
module.exports = AutocompleteControl;