@wix/form-public 0.480.0 → 0.481.0
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.cjs +72 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -46403,10 +46403,10 @@ var require_src2 = __commonJS({
|
|
|
46403
46403
|
return typeof value === "object";
|
|
46404
46404
|
}
|
|
46405
46405
|
exports.isObject = isObject7;
|
|
46406
|
-
function
|
|
46406
|
+
function isPlainObject2(value) {
|
|
46407
46407
|
return isObject7(value) && Object.prototype.toString.call(value) === "[object Object]";
|
|
46408
46408
|
}
|
|
46409
|
-
exports.isPlainObject =
|
|
46409
|
+
exports.isPlainObject = isPlainObject2;
|
|
46410
46410
|
function isRegExp2(value) {
|
|
46411
46411
|
return Object.prototype.toString.call(value) === "[object RegExp]";
|
|
46412
46412
|
}
|
|
@@ -49501,13 +49501,13 @@ var DayOfWeek3;
|
|
|
49501
49501
|
DayOfWeek5["SUNDAY"] = "SUNDAY";
|
|
49502
49502
|
})(DayOfWeek3 || (DayOfWeek3 = {}));
|
|
49503
49503
|
var ValidationFormat7;
|
|
49504
|
-
(function(
|
|
49505
|
-
|
|
49506
|
-
|
|
49507
|
-
|
|
49508
|
-
|
|
49509
|
-
|
|
49510
|
-
|
|
49504
|
+
(function(ValidationFormat10) {
|
|
49505
|
+
ValidationFormat10["UNDEFINED"] = "UNDEFINED";
|
|
49506
|
+
ValidationFormat10["WIX_FILE"] = "WIX_FILE";
|
|
49507
|
+
ValidationFormat10["PAYMENT"] = "PAYMENT";
|
|
49508
|
+
ValidationFormat10["MULTILINE_ADDRESS"] = "MULTILINE_ADDRESS";
|
|
49509
|
+
ValidationFormat10["SCHEDULING"] = "SCHEDULING";
|
|
49510
|
+
ValidationFormat10["OBJECT_ARRAY"] = "OBJECT_ARRAY";
|
|
49511
49511
|
})(ValidationFormat7 || (ValidationFormat7 = {}));
|
|
49512
49512
|
var Format6;
|
|
49513
49513
|
(function(Format9) {
|
|
@@ -54686,6 +54686,63 @@ var mergeErrors = ({ errors, additionalErrors }) => {
|
|
|
54686
54686
|
...errorsToAdd
|
|
54687
54687
|
];
|
|
54688
54688
|
};
|
|
54689
|
+
var ADDRESS_DISCRIMINATOR = "country";
|
|
54690
|
+
function omitHiddenValues(form, values) {
|
|
54691
|
+
const nestedFormsByTarget = getNestedFormsByTarget(form);
|
|
54692
|
+
return (form.fields ?? []).reduce((result2, field) => {
|
|
54693
|
+
const target = field.target;
|
|
54694
|
+
if (!target || !(target in result2)) {
|
|
54695
|
+
return result2;
|
|
54696
|
+
}
|
|
54697
|
+
if (field.hidden) {
|
|
54698
|
+
delete result2[target];
|
|
54699
|
+
return result2;
|
|
54700
|
+
}
|
|
54701
|
+
const nestedForm = field.nestedFormId ? nestedFormsByTarget?.[target] : getObjectArrayForm(field);
|
|
54702
|
+
if (nestedForm) {
|
|
54703
|
+
result2[target] = omitHiddenNestedValues(nestedForm, result2[target]);
|
|
54704
|
+
return result2;
|
|
54705
|
+
}
|
|
54706
|
+
if (isMultilineAddress(field)) {
|
|
54707
|
+
result2[target] = omitHiddenAddressValues(field, result2[target]);
|
|
54708
|
+
}
|
|
54709
|
+
return result2;
|
|
54710
|
+
}, {
|
|
54711
|
+
...values
|
|
54712
|
+
});
|
|
54713
|
+
}
|
|
54714
|
+
function omitHiddenNestedValues(form, value) {
|
|
54715
|
+
if (Array.isArray(value)) {
|
|
54716
|
+
return value.map((item) => isPlainObject(item) ? omitHiddenValues(form, item) : item);
|
|
54717
|
+
}
|
|
54718
|
+
return isPlainObject(value) ? omitHiddenValues(form, value) : value;
|
|
54719
|
+
}
|
|
54720
|
+
function omitHiddenAddressValues(field, value) {
|
|
54721
|
+
const fieldSettings = field.view?.fieldSettings;
|
|
54722
|
+
if (!fieldSettings || !isPlainObject(value)) {
|
|
54723
|
+
return value;
|
|
54724
|
+
}
|
|
54725
|
+
const result2 = {
|
|
54726
|
+
...value
|
|
54727
|
+
};
|
|
54728
|
+
Object.entries(fieldSettings).forEach(([subTarget, settings]) => {
|
|
54729
|
+
if (settings?.show === false && subTarget !== ADDRESS_DISCRIMINATOR) {
|
|
54730
|
+
delete result2[subTarget];
|
|
54731
|
+
}
|
|
54732
|
+
});
|
|
54733
|
+
return result2;
|
|
54734
|
+
}
|
|
54735
|
+
function getObjectArrayForm(field) {
|
|
54736
|
+
return field.validation?.predefined?.format === types.ValidationFormat.OBJECT_ARRAY ? {
|
|
54737
|
+
fields: field.view?.fields ?? []
|
|
54738
|
+
} : void 0;
|
|
54739
|
+
}
|
|
54740
|
+
function isMultilineAddress(field) {
|
|
54741
|
+
return field.validation?.predefined?.format === types.ValidationFormat.MULTILINE_ADDRESS;
|
|
54742
|
+
}
|
|
54743
|
+
function isPlainObject(value) {
|
|
54744
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
54745
|
+
}
|
|
54689
54746
|
|
|
54690
54747
|
// ../form-viewer/dist/esm/services/form-overrides.js
|
|
54691
54748
|
function applyFormOverrides2(form, overrides, recursive = true) {
|
|
@@ -55372,12 +55429,13 @@ var useSubmit = ({ validateAndScrollToError, submitAction, onSubmit, onSubmitSuc
|
|
|
55372
55429
|
var useValidation = ({ form, errorsRef, setErrors, validationMode }) => {
|
|
55373
55430
|
const { addressTemplates } = useAddressForms();
|
|
55374
55431
|
const externalData = useExternalData();
|
|
55375
|
-
const validateFields2 = React171.useCallback(async (newValues) => {
|
|
55376
|
-
const
|
|
55432
|
+
const validateFields2 = React171.useCallback(async (newValues, { skipHidden } = {}) => {
|
|
55433
|
+
const values = skipHidden ? omitHiddenValues(form, newValues) : newValues;
|
|
55434
|
+
const result2 = await validate(form, values, addressTemplates, validationMode);
|
|
55377
55435
|
const _errors = result2?.errors || [];
|
|
55378
55436
|
const additionalErrors = runAdditionalValidation({
|
|
55379
55437
|
form,
|
|
55380
|
-
values
|
|
55438
|
+
values,
|
|
55381
55439
|
externalData
|
|
55382
55440
|
});
|
|
55383
55441
|
const allErrors = mergeErrors({
|
|
@@ -55542,8 +55600,8 @@ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange,
|
|
|
55542
55600
|
});
|
|
55543
55601
|
React171.useImperativeHandle(forwardedRef, () => ({
|
|
55544
55602
|
submit: submitForm,
|
|
55545
|
-
validate: async () => {
|
|
55546
|
-
const validationErrors = await validateFields2(normalizedValues);
|
|
55603
|
+
validate: async (options) => {
|
|
55604
|
+
const validationErrors = await validateFields2(normalizedValues, options);
|
|
55547
55605
|
if (validationErrors && validationErrors.length > 0) {
|
|
55548
55606
|
if (enableScrollToFirstError) {
|
|
55549
55607
|
scrollToFirstError(validationErrors);
|