| | |
| | | let data = {}; |
| | | data.repeater = repeater; |
| | | repeater.append(this.templates.create(repeater.dataset.repeaterId, data)); |
| | | this.initializeFields(repeater, this.getField(repeater).config??{}); |
| | | let form = this.getForm(repeater); |
| | | this.initializeFields(repeater, form); |
| | | this.a11y.announce('Row added'); |
| | | } |
| | | removeRepeaterRow(row) { |
| | |
| | | } |
| | | addTagListListeners(el) { |
| | | el.addEventListener('click', this.tagListClick); |
| | | el.addEventListener('keypress', this.tagListInput, {passive: true}) |
| | | el.addEventListener('keypress', this.tagListInput); |
| | | } |
| | | removeTagListListeners(el) { |
| | | el.removeEventListener('click', this.tagListClick); |
| | | el.removeEventListener('keypress', this.tagListInput) |
| | | el.removeEventListener('keypress', this.tagListInput); |
| | | } |
| | | |
| | | handleTagListClick(e) { |
| | |
| | | } |
| | | }); |
| | | } |
| | | checkForCharacterLimits(form) { |
| | | if (!form.querySelector(this.selectors.limits.hasLimit)) return; |
| | | this.countUpdaters = this.updateCount.bind(this); |
| | | checkForCharacterLimits(form) { |
| | | if (!form.querySelector(this.selectors.limits.hasLimit)) return; |
| | | this.countUpdaters = this.updateCount.bind(this); |
| | | |
| | | form.querySelectorAll(`${this.selectors.limits.hasLimit}`).forEach(input => { |
| | | let id = window.generateID('limit'); |
| | | input.dataset.charLimitId = id; |
| | | let config = { |
| | | element: input, |
| | | form: form.dataset.formId, |
| | | ui: window.uiFromSelectors(this.selectors.limits, input.closest('.field')) |
| | | }; |
| | | config.ui.limit.textContent = input.dataset.limit; |
| | | this.charLimits.set(id, config); |
| | | form.querySelectorAll(this.selectors.limits.hasLimit).forEach(field => { |
| | | const input = field.querySelector('input, textarea, select'); |
| | | if (!input) return; |
| | | |
| | | this.addCharacterLimitListeners(input); |
| | | }); |
| | | let id = window.generateID('limit'); |
| | | input.dataset.charLimitId = id; |
| | | input.dataset.limit = field.dataset.limit; |
| | | |
| | | let config = { |
| | | element: input, |
| | | form: form.dataset.formId, |
| | | ui: window.uiFromSelectors(this.selectors.limits, field) |
| | | }; |
| | | |
| | | if (config.ui.limit) { |
| | | config.ui.limit.textContent = field.dataset.limit; |
| | | } |
| | | |
| | | this.charLimits.set(id, config); |
| | | this.addCharacterLimitListeners(input); |
| | | }); |
| | | } |
| | | addCharacterLimitListeners(input) { |
| | | input.addEventListener('input', this.countUpdaters, {passive: true}); |
| | | } |
| | |
| | | }); |
| | | this.tagLists.clear(); |
| | | } |
| | | if(this.charLimits.size > 0) { |
| | | if (this.charLimits.size > 0) { |
| | | Array.from(this.charLimits.values()).forEach(charLimit => { |
| | | charLimit.removeEventListener('input', this.countUpdaters); |
| | | }) |
| | | charLimit.element.removeEventListener('input', this.countUpdaters); |
| | | }); |
| | | } |
| | | this.inputs.clear(); |
| | | this.forms.clear(); |