form-builder-pro 1.2.6 → 1.2.7
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/index.js +28 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4615,6 +4615,8 @@ function fieldToPayload(field) {
|
|
|
4615
4615
|
payload.css = field.css;
|
|
4616
4616
|
if (field.optionSource !== void 0)
|
|
4617
4617
|
payload.optionSource = field.optionSource;
|
|
4618
|
+
if (field.customOptionsEnabled !== void 0)
|
|
4619
|
+
payload.customOptionsEnabled = field.customOptionsEnabled;
|
|
4618
4620
|
if (field.groupName !== void 0)
|
|
4619
4621
|
payload.groupName = field.groupName;
|
|
4620
4622
|
if (field.masterTypeName !== void 0)
|
|
@@ -4629,8 +4631,8 @@ function fieldToPayload(field) {
|
|
|
4629
4631
|
payload.lookupLabelField = field.lookupLabelField;
|
|
4630
4632
|
if (field.isd !== void 0)
|
|
4631
4633
|
payload.isd = field.isd;
|
|
4632
|
-
if ((field.type === "select" || field.type === "radio" || field.type === "checkbox") && field.options) {
|
|
4633
|
-
payload.options = field.options;
|
|
4634
|
+
if ((field.type === "select" || field.type === "radio" || field.type === "checkbox") && field.options && Array.isArray(field.options)) {
|
|
4635
|
+
payload.options = field.options.map((opt) => ({ label: opt.label, value: opt.value }));
|
|
4634
4636
|
}
|
|
4635
4637
|
return payload;
|
|
4636
4638
|
}
|
|
@@ -9700,6 +9702,11 @@ var FormBuilder = class {
|
|
|
9700
9702
|
const shouldShowOptions = selectedField.type === "select" ? selectedField.customOptionsEnabled && (selectedField.optionSource === "STATIC" || !selectedField.optionSource) : true;
|
|
9701
9703
|
if (shouldShowOptions) {
|
|
9702
9704
|
const options = selectedField.options || [];
|
|
9705
|
+
const fieldId2 = selectedField.id;
|
|
9706
|
+
const getCurrentOptions = () => {
|
|
9707
|
+
const field = formStore.getState().schema.sections.flatMap((s) => s.fields).find((f) => f.id === fieldId2);
|
|
9708
|
+
return field?.options || [];
|
|
9709
|
+
};
|
|
9703
9710
|
const optionsList = createElement("div", { className: "space-y-2 mb-3" });
|
|
9704
9711
|
options.forEach((opt, index2) => {
|
|
9705
9712
|
const optionRow = createElement("div", { className: "flex gap-2 items-center" });
|
|
@@ -9710,9 +9717,12 @@ var FormBuilder = class {
|
|
|
9710
9717
|
placeholder: "Option label",
|
|
9711
9718
|
"data-focus-id": `field-option-label-${selectedField.id}-${index2}`,
|
|
9712
9719
|
oninput: (e) => {
|
|
9713
|
-
const
|
|
9714
|
-
newOptions
|
|
9715
|
-
|
|
9720
|
+
const currentOptions = getCurrentOptions();
|
|
9721
|
+
const newOptions = [...currentOptions];
|
|
9722
|
+
if (newOptions[index2]) {
|
|
9723
|
+
newOptions[index2] = { ...newOptions[index2], label: e.target.value };
|
|
9724
|
+
formStore.getState().updateField(fieldId2, { options: newOptions });
|
|
9725
|
+
}
|
|
9716
9726
|
}
|
|
9717
9727
|
});
|
|
9718
9728
|
const valueInput = createElement("input", {
|
|
@@ -9722,17 +9732,21 @@ var FormBuilder = class {
|
|
|
9722
9732
|
placeholder: "Option value",
|
|
9723
9733
|
"data-focus-id": `field-option-value-${selectedField.id}-${index2}`,
|
|
9724
9734
|
oninput: (e) => {
|
|
9725
|
-
const
|
|
9726
|
-
newOptions
|
|
9727
|
-
|
|
9735
|
+
const currentOptions = getCurrentOptions();
|
|
9736
|
+
const newOptions = [...currentOptions];
|
|
9737
|
+
if (newOptions[index2]) {
|
|
9738
|
+
newOptions[index2] = { ...newOptions[index2], value: e.target.value };
|
|
9739
|
+
formStore.getState().updateField(fieldId2, { options: newOptions });
|
|
9740
|
+
}
|
|
9728
9741
|
}
|
|
9729
9742
|
});
|
|
9730
9743
|
const deleteBtn = createElement("button", {
|
|
9731
9744
|
className: "p-1.5 text-red-600 hover:bg-red-50 rounded transition-colors",
|
|
9732
9745
|
title: "Delete option",
|
|
9733
9746
|
onclick: () => {
|
|
9734
|
-
const
|
|
9735
|
-
|
|
9747
|
+
const currentOptions = getCurrentOptions();
|
|
9748
|
+
const newOptions = currentOptions.filter((_, i) => i !== index2);
|
|
9749
|
+
formStore.getState().updateField(fieldId2, { options: newOptions });
|
|
9736
9750
|
}
|
|
9737
9751
|
}, [getIcon("Trash2", 14)]);
|
|
9738
9752
|
optionRow.appendChild(labelInput);
|
|
@@ -9746,8 +9760,10 @@ var FormBuilder = class {
|
|
|
9746
9760
|
className: "w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-700 rounded-md hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors",
|
|
9747
9761
|
text: "Add Option",
|
|
9748
9762
|
onclick: () => {
|
|
9749
|
-
const
|
|
9750
|
-
|
|
9763
|
+
const currentOptions = getCurrentOptions();
|
|
9764
|
+
const newOption = { label: `Option ${currentOptions.length + 1}`, value: `opt${currentOptions.length + 1}` };
|
|
9765
|
+
const newOptions = [...currentOptions, newOption];
|
|
9766
|
+
formStore.getState().updateField(fieldId2, { options: newOptions });
|
|
9751
9767
|
this.render();
|
|
9752
9768
|
}
|
|
9753
9769
|
});
|