mirror of
https://github.com/frappe/books.git
synced 2024-11-10 15:50:56 +00:00
34 lines
906 B
JavaScript
34 lines
906 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.get_list(this.input.value);
|
|
});
|
|
}
|
|
|
|
async get_list(query) {
|
|
return (await frappe.db.get_all({
|
|
doctype: this.target,
|
|
filters: this.get_filters(query),
|
|
limit: 50
|
|
})).map(d => d.name);
|
|
}
|
|
|
|
get_filters(query) {
|
|
return { keywords: ["like", query] }
|
|
}
|
|
};
|
|
|
|
module.exports = LinkControl; |