Sha256: f47f09ca568cf583115a3d3c0a20fe48d158414f34191b8c353ca556a756bda9
Contents?: true
Size: 1.16 KB
Versions: 25
Compression:
Stored size: 1.16 KB
Contents
export default class Work { // Autocomplete for finding possible related works. constructor(element, url, excludeWorkId) { this.url = url; this.excludeWorkId = excludeWorkId; this.initUI(element) } initUI(element) { element.select2( { minimumInputLength: 2, initSelection : (row, callback) => { var data = {id: row.val(), text: row.val()}; callback(data); }, ajax: { // instead of writing the function to execute the request we use Select2's convenient helper url: this.url, dataType: 'json', data: (term, page) => { return { q: term, // search term id: this.excludeWorkId // Exclude this work }; }, results: this.processResults } }).select2('data', null); } // parse the results into the format expected by Select2. // since we are using custom formatting functions we do not need to alter remote JSON data processResults(data, page) { let results = data.map((obj) => { return { id: obj.id, text: obj.label[0] }; }) return { results: results }; } }
Version data entries
25 entries across 25 versions & 2 rubygems