2
0
mirror of https://github.com/frappe/books.git synced 2024-09-21 03:39:02 +00:00
books/client/view/controls/link.js
2018-02-08 15:08:47 +05:30

34 lines
901 B
JavaScript

const frappe = require('frappejs');
const BaseControl = require('./base');
const Awesomplete = require('awesomplete');
class LinkControl extends BaseControl {
make() {
super.make();
this.input.setAttribute('type', 'text');
this.awesomplete = new Awesomplete(this.input, {
autoFirst: true,
minChars: 0,
maxItems: 99
});
// rebuild the list on input
this.input.addEventListener('input', async (event) => {
this.awesomplete.list = await this.getList(this.input.value);
});
}
async getList(query) {
return (await frappe.db.getAll({
doctype: this.target,
filters: this.getFilters(query),
limit: 50
})).map(d => d.name);
}
getFilters(query) {
return { keywords: ["like", query] }
}
};
module.exports = LinkControl;