2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +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(); this.setupAwesomplete();
} }
setupAwesomplete() { async setupAwesomplete() {
this.awesomplete = new Awesomplete(this.input, { this.awesomplete = new Awesomplete(this.input, {
minChars: 0, minChars: 0,
maxItems: 99 maxItems: 99
}); });
this.list = await this.getList();
// rebuild the list on input // rebuild the list on input
this.input.addEventListener('input', async (event) => { this.input.addEventListener('input', (event) => {
let list = await this.getList(); this.awesomplete.list = this.list;
this.awesomplete.list = list;
}); });
} }
validate(value) {
if (this.list.includes(value)) {
return value;
}
return false;
}
}; };
module.exports = AutocompleteControl; module.exports = AutocompleteControl;