| | |
| | | populateField(field, name, value) { |
| | | |
| | | let type = this.formHelper.getFieldType(field); |
| | | if (!type || this.isEmptyValue(name) || this.isEmptyValue(value)) return; |
| | | if (!type || this.isEmptyValue(name)) return; |
| | | |
| | | const handlers = { |
| | | 'repeater': this.populateRepeater.bind(this), |
| | |
| | | } |
| | | |
| | | populateRepeater(field, name, value) { |
| | | if (!value || !Array.isArray(value)) return; |
| | | |
| | | const container = field.querySelector('.repeater-items'); |
| | | let template = field.querySelector('template')?.className ?? false; |
| | | if (!container || !template) return; |
| | | |
| | | // Normalize: server/store may return an object with numeric keys instead of an array |
| | | if (typeof value === 'string') { |
| | | try { value = JSON.parse(value); } catch(e) { value = []; } |
| | | } |
| | | if (value && !Array.isArray(value) && typeof value === 'object') { |
| | | value = Object.values(value); |
| | | } |
| | | |
| | | if (!value || !Array.isArray(value) || value.length === 0) { |
| | | window.removeChildren(container); |
| | | return; |
| | | } |
| | | |
| | | window.removeChildren(container); |
| | | |
| | | value.forEach((data, index) => { |
| | |
| | | }); |
| | | } |
| | | populateTagList(field, name, value) { |
| | | if (!value || !Array.isArray(value)) return; |
| | | |
| | | const container = field.querySelector('.tag-items'); |
| | | let template = field.querySelector('template')?.className ?? false; |
| | | if (!container || !template) return; |
| | | |
| | | if (typeof value === 'string') { |
| | | try { value = JSON.parse(value); } catch(e) { value = []; } |
| | | } |
| | | if (value && !Array.isArray(value) && typeof value === 'object') { |
| | | value = Object.values(value); |
| | | } |
| | | |
| | | if (!value || !Array.isArray(value) || value.length === 0) { |
| | | window.removeChildren(container); |
| | | return; |
| | | } |
| | | |
| | | window.removeChildren(container); |
| | | |
| | | value.forEach((data, index) => { |
| | |
| | | } |
| | | populateTaxonomy(field, name, value) { |
| | | let termIds = this.splitIDs(value); |
| | | if (termIds.length === 0) return; |
| | | |
| | | const hiddenInput = field.querySelector(`input[type="hidden"][name="${name}"]`); |
| | | if (hiddenInput) { |
| | |
| | | return; |
| | | } |
| | | |
| | | if (this.isEmptyValue(value)) return; |
| | | const ids = this.splitIDs(value); |
| | | if (ids.length === 0) return; |
| | | const hiddenInput = field.querySelector(`input[type="hidden"]`); |