formeo 5.3.2 → 5.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 5.3.1
4
+ Version: 5.3.2
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -8068,7 +8068,7 @@ Author: Draggable https://draggable.io
8068
8068
  })), name$1, version$2, type, main, module$1, unpkg, exports$1, files, homepage, repository, author, contributors, bugs, description, keywords, ignore, config, scripts, devDependencies, dependencies, release, commitlint, package_default;
8069
8069
  var init_package = __esmMin((() => {
8070
8070
  name$1 = "formeo";
8071
- version$2 = "5.3.1";
8071
+ version$2 = "5.3.2";
8072
8072
  type = "module";
8073
8073
  main = "dist/formeo.cjs.js";
8074
8074
  module$1 = "dist/formeo.es.js";
@@ -8681,7 +8681,7 @@ Author: Draggable https://draggable.io
8681
8681
  function trimKeyPrefix(key) {
8682
8682
  return key.replaceAll(keyPrefixRegex, "");
8683
8683
  }
8684
- var toTitleCaseLowers, toTitleCaseRegex, regexSpace, slugify, splitAddress, slugifyAddress, extractTextFromHtml, truncateByWord, keyPrefixRegex;
8684
+ var toTitleCaseLowers, toTitleCaseRegex, regexSpace, slugify, splitAddress, slugifyAddress, extractTextFromHtml, truncateByWord, keyPrefixRegex, groupInputName;
8685
8685
  var init_string = __esmMin((() => {
8686
8686
  toTitleCaseLowers = "a an and as at but by for for from in into near nor of on onto or the to with".split(" ").map((lower) => String.raw`\s${lower}\s`);
8687
8687
  toTitleCaseRegex = new RegExp(String.raw`(?!${toTitleCaseLowers.join("|")})\w\S*`, "g");
@@ -8718,6 +8718,7 @@ Author: Draggable https://draggable.io
8718
8718
  return truncatedWord;
8719
8719
  };
8720
8720
  keyPrefixRegex = /^attrs\.|^meta\.|^options\.|^config\./g;
8721
+ groupInputName = (name, fieldType, optionCount) => fieldType === "checkbox" && optionCount > 1 && name && !name.endsWith("[]") ? `${name}[]` : name;
8721
8722
  }));
8722
8723
  //#endregion
8723
8724
  //#region src/lib/js/common/events.js
@@ -17220,7 +17221,7 @@ Author: Draggable https://draggable.io
17220
17221
  const { action, attrs = {} } = elem;
17221
17222
  const fieldType = attrs.type || elem.tag;
17222
17223
  const id = attrs.id || elem.id;
17223
- const name = !isPreview && attrs.name || id;
17224
+ const name = isPreview ? id : groupInputName(attrs.name || id, fieldType, options.length);
17224
17225
  const sharedInputAttrs = Object.fromEntries(OPTION_INPUT_ATTRS.filter((key) => key in attrs).map((key) => [key, attrs[key]]));
17225
17226
  if (attrs.required) sharedInputAttrs.required = fieldType !== "checkbox" || !options.some(({ selected, checked }) => selected || checked);
17226
17227
  const optionMap = (option, i) => {
@@ -18486,12 +18487,12 @@ Author: Draggable https://draggable.io
18486
18487
  * @return {Object|undefined}
18487
18488
  */
18488
18489
  componentByName(name) {
18489
- return this.components[baseId(name)] || Object.values(this.components).find((component) => component.attrs?.name === name);
18490
+ return this.components[baseId(name)] || Object.values(this.components).find((component) => component.attrs?.name === name || component.attrs?.name === `${name}[]`);
18490
18491
  }
18491
18492
  set userData(data = {}) {
18492
18493
  const form = this.container.querySelector("form");
18493
18494
  for (const key of Object.keys(data)) {
18494
- const fields = form.elements[key];
18495
+ const fields = form.elements[key] ?? form.elements[`${key}[]`];
18495
18496
  const checkables = checkableInputs(fields);
18496
18497
  if (checkables?.[0].type === "checkbox") {
18497
18498
  const values = Array.isArray(data[key]) ? data[key] : [data[key]];
@@ -18777,11 +18778,12 @@ Author: Draggable https://draggable.io
18777
18778
  };
18778
18779
  getComponents = (address) => {
18779
18780
  const components = [];
18780
- const componentId = address.slice(address.indexOf(".") + 1);
18781
- components.push(...this.renderedForm.querySelectorAll(`[name=f-${componentId}]`));
18781
+ const name = `f-${address.slice(address.indexOf(".") + 1)}`;
18782
+ components.push(...this.renderedForm.querySelectorAll(`[name="${name}"], [name="${name}[]"]`));
18782
18783
  return components;
18783
18784
  };
18784
18785
  };
18786
+ var fieldKey = (key) => key.endsWith("[]") ? key.slice(0, -2) : key;
18785
18787
  /**
18786
18788
  * Converts a rendered form's fields to a plain object, the same shape the `userData`
18787
18789
  * getter exposes. Handles multiple values for the same key by converting them to arrays.
@@ -18792,9 +18794,12 @@ Author: Draggable https://draggable.io
18792
18794
  if (!form) return {};
18793
18795
  const formEntries = new FormData(form);
18794
18796
  const formDataObj = {};
18795
- for (const [key, value] of formEntries.entries()) if (Object.hasOwn(formDataObj, key)) if (Array.isArray(formDataObj[key])) formDataObj[key].push(value);
18796
- else formDataObj[key] = [formDataObj[key], value];
18797
- else formDataObj[key] = value;
18797
+ for (const [rawKey, value] of formEntries.entries()) {
18798
+ const key = fieldKey(rawKey);
18799
+ if (Object.hasOwn(formDataObj, key)) if (Array.isArray(formDataObj[key])) formDataObj[key].push(value);
18800
+ else formDataObj[key] = [formDataObj[key], value];
18801
+ else formDataObj[key] = value;
18802
+ }
18798
18803
  return formDataObj;
18799
18804
  };
18800
18805
  var isCheckable = (elem) => ["checkbox", "radio"].includes(elem?.type);