Sha256: 722929ff36fdb529d19683344703e6c0f5b671431fd6dec972f0c6fffaf33ff8
Contents?: true
Size: 1.19 KB
Versions: 19
Compression:
Stored size: 1.19 KB
Contents
class TagsAutocomplete extends HTMLElement { connectedCallback() { this.classList.add("autocomplete_tag_list") $(this.input).select2(this.select2Config) } get input() { return this.getElementsByTagName("input")[0] } get select2Config() { return { tags: true, tokenSeparators: [","], openOnEnter: false, minimumInputLength: 1, createSearchChoice: this.#createSearchChoice, ajax: { url: this.getAttribute("url"), dataType: "json", data: (term) => { return { term } }, results: (data) => { return { results: data } } }, initSelection: this.#initSelection } } #createSearchChoice(term, data) { if ( $(data).filter(function () { return this.text.localeCompare(term) === 0 }).length === 0 ) { return { id: term, text: term } } } #initSelection(element, callback) { const data = [] $(element.val().split(",")).each(function () { data.push({ id: this.trim(), text: this }) }) callback(data) } } customElements.define("alchemy-tags-autocomplete", TagsAutocomplete)
Version data entries
19 entries across 19 versions & 1 rubygems