@dmitryvim/form-builder 0.2.16 → 0.2.17
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.
- package/dist/browser/formbuilder.min.js +71 -71
- package/dist/browser/formbuilder.v0.2.17.min.js +358 -0
- package/dist/cjs/index.cjs +30 -22
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +30 -22
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +71 -71
- package/package.json +1 -1
- package/dist/browser/formbuilder.v0.2.16.min.js +0 -358
package/dist/esm/index.js
CHANGED
|
@@ -3877,10 +3877,7 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3877
3877
|
rem.addEventListener("mouseleave", () => {
|
|
3878
3878
|
rem.style.backgroundColor = "transparent";
|
|
3879
3879
|
});
|
|
3880
|
-
rem.onclick = () =>
|
|
3881
|
-
item.remove();
|
|
3882
|
-
updateAddButton();
|
|
3883
|
-
};
|
|
3880
|
+
rem.onclick = () => handleRemoveItem(item);
|
|
3884
3881
|
item.style.position = "relative";
|
|
3885
3882
|
item.appendChild(rem);
|
|
3886
3883
|
}
|
|
@@ -3902,6 +3899,10 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3902
3899
|
}
|
|
3903
3900
|
countDisplay.textContent = `${currentCount}/${max === Infinity ? "\u221E" : max}`;
|
|
3904
3901
|
};
|
|
3902
|
+
const handleRemoveItem = (item) => {
|
|
3903
|
+
item.remove();
|
|
3904
|
+
updateAddButton();
|
|
3905
|
+
};
|
|
3905
3906
|
if (pre && Array.isArray(pre)) {
|
|
3906
3907
|
pre.forEach((prefillObj, idx) => {
|
|
3907
3908
|
const mergedPrefill = mergeWithDefaults(prefillObj || {}, childDefaults);
|
|
@@ -3945,10 +3946,7 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3945
3946
|
rem.addEventListener("mouseleave", () => {
|
|
3946
3947
|
rem.style.backgroundColor = "transparent";
|
|
3947
3948
|
});
|
|
3948
|
-
rem.onclick = () =>
|
|
3949
|
-
item.remove();
|
|
3950
|
-
updateAddButton();
|
|
3951
|
-
};
|
|
3949
|
+
rem.onclick = () => handleRemoveItem(item);
|
|
3952
3950
|
item.style.position = "relative";
|
|
3953
3951
|
item.appendChild(rem);
|
|
3954
3952
|
}
|
|
@@ -3999,8 +3997,7 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
|
|
|
3999
3997
|
});
|
|
4000
3998
|
rem.onclick = () => {
|
|
4001
3999
|
if (countItems() > min) {
|
|
4002
|
-
item
|
|
4003
|
-
updateAddButton();
|
|
4000
|
+
handleRemoveItem(item);
|
|
4004
4001
|
}
|
|
4005
4002
|
};
|
|
4006
4003
|
item.style.position = "relative";
|
|
@@ -4058,15 +4055,16 @@ function validateContainerElement(element, key, context) {
|
|
|
4058
4055
|
"[data-container-item]"
|
|
4059
4056
|
);
|
|
4060
4057
|
const containerWrappers = Array.from(allContainerWrappers).filter((el) => {
|
|
4061
|
-
const attr = el.getAttribute("data-container-item");
|
|
4062
|
-
|
|
4058
|
+
const attr = el.getAttribute("data-container-item") || "";
|
|
4059
|
+
if (!attr.startsWith(`${key}[`)) return false;
|
|
4060
|
+
const suffix = attr.slice(key.length);
|
|
4061
|
+
return /^\[\d+\]$/.test(suffix);
|
|
4063
4062
|
});
|
|
4064
|
-
|
|
4065
|
-
for (let i = 0; i < itemCount; i++) {
|
|
4063
|
+
containerWrappers.forEach((itemContainer) => {
|
|
4066
4064
|
const itemData = {};
|
|
4067
|
-
const
|
|
4068
|
-
|
|
4069
|
-
)
|
|
4065
|
+
const containerAttr = itemContainer.getAttribute("data-container-item") || "";
|
|
4066
|
+
const indexMatch = containerAttr.match(/\[(\d+)\]$/);
|
|
4067
|
+
const domIndex = indexMatch ? parseInt(indexMatch[1], 10) : 0;
|
|
4070
4068
|
element.elements.forEach((child) => {
|
|
4071
4069
|
if (child.enableIf) {
|
|
4072
4070
|
try {
|
|
@@ -4083,7 +4081,7 @@ function validateContainerElement(element, key, context) {
|
|
|
4083
4081
|
}
|
|
4084
4082
|
} catch (error) {
|
|
4085
4083
|
console.error(
|
|
4086
|
-
`Error evaluating enableIf for field "${child.key}" in container "${key}[${
|
|
4084
|
+
`Error evaluating enableIf for field "${child.key}" in container "${key}[${domIndex}]":`,
|
|
4087
4085
|
error
|
|
4088
4086
|
);
|
|
4089
4087
|
}
|
|
@@ -4091,7 +4089,7 @@ function validateContainerElement(element, key, context) {
|
|
|
4091
4089
|
if (child.hidden || child.type === "hidden") {
|
|
4092
4090
|
itemData[child.key] = child.default !== void 0 ? child.default : null;
|
|
4093
4091
|
} else {
|
|
4094
|
-
const childKey = `${key}[${
|
|
4092
|
+
const childKey = `${key}[${domIndex}].${child.key}`;
|
|
4095
4093
|
itemData[child.key] = validateElement(
|
|
4096
4094
|
{ ...child, key: childKey },
|
|
4097
4095
|
{ path },
|
|
@@ -4100,7 +4098,7 @@ function validateContainerElement(element, key, context) {
|
|
|
4100
4098
|
}
|
|
4101
4099
|
});
|
|
4102
4100
|
items.push(itemData);
|
|
4103
|
-
}
|
|
4101
|
+
});
|
|
4104
4102
|
validateContainerCount(key, items, element);
|
|
4105
4103
|
return { value: items, errors };
|
|
4106
4104
|
} else {
|
|
@@ -5751,8 +5749,18 @@ var FormBuilderInstance = class {
|
|
|
5751
5749
|
if ((element.type === "container" || element.type === "group") && "elements" in element && element.elements) {
|
|
5752
5750
|
const containerData = formData?.[element.key];
|
|
5753
5751
|
if (Array.isArray(containerData)) {
|
|
5754
|
-
|
|
5755
|
-
|
|
5752
|
+
const containerItems = this.state.formRoot.querySelectorAll(
|
|
5753
|
+
`[data-container-item]`
|
|
5754
|
+
);
|
|
5755
|
+
const directItems = Array.from(containerItems).filter((el) => {
|
|
5756
|
+
const attr = el.getAttribute("data-container-item") || "";
|
|
5757
|
+
if (!attr.startsWith(`${fullPath}[`)) return false;
|
|
5758
|
+
const suffix = attr.slice(fullPath.length);
|
|
5759
|
+
return /^\[\d+\]$/.test(suffix);
|
|
5760
|
+
});
|
|
5761
|
+
directItems.forEach((el) => {
|
|
5762
|
+
const attr = el.getAttribute("data-container-item") || "";
|
|
5763
|
+
checkElements(element.elements, attr);
|
|
5756
5764
|
});
|
|
5757
5765
|
} else {
|
|
5758
5766
|
checkElements(element.elements, fullPath);
|