UNPKG

getaddress-autocomplete-modal

Version:

GetAddress.io - Autocomplete modal plug-in

40 lines 1.55 kB
import { Debug } from "./Debug.js"; export default class ClearButton { constructor(input, attributeValues) { this.input = input; this.attributeValues = attributeValues; this.button = document.createElement('BUTTON'); this.element = this.button; this.build = () => { this.element.setAttribute('disabled', ''); const icon = document.createElement('i'); icon.className = this.attributeValues.iconCancelClassName; icon.classList.add(this.attributeValues.iconClassName); this.button.insertAdjacentElement('afterbegin', icon); this.button.className = this.attributeValues.backButtonClassName; this.button.classList.add(this.attributeValues.buttonClassName); this.input.element.addEventListener('input', (e) => { this.setDisabled(); }); this.button.addEventListener('click', this.handleClick); }; this.setDisabled = () => { if (this.input.element.value) { this.element.removeAttribute('disabled'); } else { this.element.setAttribute('disabled', ''); } }; this.handleClick = (e) => { Debug.Log(this.attributeValues, e); this.input.clear(); this.input.focus(); }; this.build(); } destroy() { this.button.removeEventListener('click', this.handleClick); } } //# sourceMappingURL=ClearButton.js.map