2
0
mirror of https://github.com/frappe/books.git synced 2025-02-04 13:08:29 +00:00

34 lines
901 B
JavaScript
Raw Normal View History

2018-01-23 17:56:40 +05:30
const frappe = require('frappejs');
const BaseControl = require('./base');
const Awesomplete = require('awesomplete');
class LinkControl extends BaseControl {
make() {
super.make();
2018-01-23 18:01:09 +05:30
this.input.setAttribute('type', 'text');
this.awesomplete = new Awesomplete(this.input, {
autoFirst: true,
minChars: 0,
maxItems: 99
});
2018-01-23 17:56:40 +05:30
2018-01-23 18:01:09 +05:30
// rebuild the list on input
this.input.addEventListener('input', async (event) => {
2018-02-08 15:08:47 +05:30
this.awesomplete.list = await this.getList(this.input.value);
2018-01-23 18:01:09 +05:30
});
2018-01-23 17:56:40 +05:30
}
2018-01-23 18:18:27 +05:30
2018-02-08 15:08:47 +05:30
async getList(query) {
return (await frappe.db.getAll({
2018-01-31 18:26:21 +05:30
doctype: this.target,
2018-02-08 15:08:47 +05:30
filters: this.getFilters(query),
2018-01-23 18:18:27 +05:30
limit: 50
})).map(d => d.name);
}
2018-02-08 15:08:47 +05:30
getFilters(query) {
2018-01-23 18:18:27 +05:30
return { keywords: ["like", query] }
}
2018-01-23 17:56:40 +05:30
};
module.exports = LinkControl;