Sha256: 5d3f3c364ec4ed5e7617c7240b7bc75f2ff509c8e17b5dd4b65b9135ae474511
Contents?: true
Size: 1.62 KB
Versions: 2
Compression:
Stored size: 1.62 KB
Contents
import Combobox from "hw_combobox/models/combobox/base" import { applyFilter, debounce, isDeleteEvent, unselectedPortion } from "hw_combobox/helpers" import { get } from "hw_combobox/vendor/requestjs" Combobox.Filtering = Base => class extends Base { filter(event) { if (this._isAsync) { this._debouncedFilterAsync(event) } else { this._filterSync(event) } } _initializeFiltering() { this._debouncedFilterAsync = debounce(this._debouncedFilterAsync.bind(this)) } _debouncedFilterAsync(event) { this._filterAsync(event) } async _filterAsync(event) { const query = { q: this._fullQuery, input_type: event.inputType, for_id: this.element.dataset.asyncId } await get(this.asyncSrcValue, { responseKind: "turbo-stream", query }) } _filterSync(event) { this.open() this._allOptionElements.forEach(applyFilter(this._fullQuery, { matching: this.filterableAttributeValue })) this._commitFilter(event) } _commitFilter(event) { if (this._shouldTreatAsNewOptionForFiltering(!isDeleteEvent(event))) { this._selectNew() } else if (isDeleteEvent(event)) { this._deselect() } else if (this._isOpen) { this._select(this._visibleOptionElements[0]) } } _clearQuery() { this._fullQuery = "" this.filter({ inputType: "deleteContentBackward" }) } get _isQueried() { return this._fullQuery.length > 0 } get _fullQuery() { return this._actingCombobox.value } set _fullQuery(value) { this._actingCombobox.value = value } get _typedQuery() { return unselectedPortion(this._actingCombobox) } }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hotwire_combobox-0.1.40 | app/assets/javascripts/hw_combobox/models/combobox/filtering.js |
hotwire_combobox-0.1.39 | app/assets/javascripts/hw_combobox/models/combobox/filtering.js |