Jake Vanderwerf
2026-02-14 27fb820ae9081fb56957cf75e79eccd8a99edd52
assets/js/concise/PopulateForm.js
@@ -64,20 +64,25 @@
      const handlers = {
         'repeater': this.populateRepeater.bind(this),
         'tag-list': this.populateTagList.bind(this),
         'group': this.populateGroup.bind(this),
         'location': this.populateLocation.bind(this),
         'selector': this.populateTaxonomy.bind(this),
         'user':  this.populateUser.bind(this),
         'upload':   this.populateUpload.bind(this),
         'gallery':  this.populateUpload.bind(this),
         'image':    this.populateUpload.bind(this),
         'set':      this.populateMultiValue.bind(this),
         'checkbox': this.populateMultiValue.bind(this),
         'select':   this.populateSingleValue.bind(this),
         'radio': this.populateSingleValue.bind(this),
         'true-false': this.populateBoolean.bind(this),
         'toggle-text': this.populateBoolean.bind(this),
         'date':  this.populateDate.bind(this),
         'time':  this.populateDate.bind(this),
         'datetime': this.populateDate.bind(this),
         'number':   this.populateNumber.bind(this),
         'textarea': this.populateTextarea.bind(this)
         'textarea': this.populateTextarea.bind(this),
         'quantity': this.populateNumber.bind(this),
      };
      if (Object.hasOwn(handlers, type)) {
@@ -97,19 +102,24 @@
      window.removeChildren(container);
      value.forEach((data, index) => {
         data.index = index;
         const row = this.templates.create(template, data);
         const templateData = { ...data, index, repeater: field };
         const row = this.templates.create(template, templateData);
         if (!row) return;
         container.append(row);
         const formConfig = this.formHelper.getForm(row);
         if (formConfig) {
            this.formHelper.initializeFields(row, formConfig);
         }
         for (let [fieldName, fieldValue] of Object.entries(data)) {
            if (fieldName === 'index') continue;
            let subField = row.querySelector(`[data-field="${fieldName}"]`);
            if (subField) {
               this.populateField(subField, fieldName, fieldValue);
            }
         }
         container.append(row);
      });
   }
   populateTagList(field, name, value) {
@@ -161,7 +171,16 @@
            return data[format] ?? values[0] ?? 'New Item';
      }
   }
   populateGroup(field, name, value) {
      if (!value || typeof value !== 'object') return;
      for (let [subName, subValue] of Object.entries(value)) {
         let subField = field.querySelector(`[data-field="${subName}"]`);
         if (subField) {
            this.populateField(subField, subName, subValue);
         }
      }
   }
   populateLocation(field, name, value) {
      const subFields = ['address', 'lat', 'lng', 'street', 'city', 'province', 'postal_code', 'country'];
      subFields.forEach(subField => {
@@ -283,7 +302,7 @@
         }
         return;
      }
      field.querySelectorAll(`[type="checkbox"][name=${name}]`).forEach(checkbox => {
      field.querySelectorAll(`input[type="checkbox"][name="${name}[]"], input[type="checkbox"][name="${name}"]`).forEach(checkbox => {
         checkbox.checked = value.includes(checkbox.value);
      });
@@ -343,17 +362,23 @@
      }
   }
   populateTextarea(field, name, value) {
      let textarea = field.querySelector('textarea');
      if (!textarea.dataset.editor) {
         this.populateText(field, name, value)
         return;
      }
      textarea.value = String(value || '');
      let textarea = field.querySelector('textarea[data-editor], textarea');
      this.populateText(field, name, value);
      if (textarea?.dataset.editor) {
         const editor = field.querySelector('.ql-editor');
         if (editor) {
            editor.innerHTML = value;
         } else {
      textarea.dispatchEvent(new Event('change', {bubbles: true}));
   }
      }
   }
   populateText(field, name, value) {
      let input = field.querySelector(`[name="${name}"], input, textarea`);
      if (input && input.type !== 'file') {
      let input = field.querySelector(`[name="${name}"]`)
         || field.querySelector('textarea[data-editor]')
         || field.querySelector('input:not([type="hidden"]):not([type="file"]), textarea, select');
      if (input) {
         input.value = String(value || '');
      }
   }