@bombillazo/rhf-plus 7.62.0-plus.6 → 7.62.0-plus.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/README.md +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +82 -4
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/logic/createFormControl.d.ts.map +1 -1
- package/dist/logic/validateField.d.ts +1 -1
- package/dist/logic/validateField.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +77 -4
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/form.d.ts +3 -0
- package/dist/types/form.d.ts.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EACX,YAAY,EAgBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EACX,YAAY,EAgBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAwDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,SAAS,SAAS,YAAY,GAAG,GAAG,EAEpC,KAAK,GAAE,YAAY,CACjB,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,SAAS,CACL,GACL,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,CAAC;CACH,CAovDA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Field, FieldValues, InternalFieldErrors, InternalNameSet } from '../types';
|
|
2
|
-
declare const _default: <T extends FieldValues>(field: Field,
|
|
2
|
+
declare const _default: <T extends FieldValues>(field: Field, skippedFieldNames: InternalNameSet, formValues: T, validateAllFieldCriteria: boolean, shouldUseNativeValidation?: boolean, isFieldArray?: boolean) => Promise<InternalFieldErrors>;
|
|
3
3
|
export default _default;
|
|
4
4
|
//# sourceMappingURL=validateField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateField.d.ts","sourceRoot":"","sources":["../../src/logic/validateField.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EAEL,WAAW,EACX,mBAAmB,EACnB,eAAe,EAKhB,MAAM,UAAU,CAAC;yBAsBI,CAAC,SAAS,WAAW,EACzC,OAAO,KAAK,EACZ,
|
|
1
|
+
{"version":3,"file":"validateField.d.ts","sourceRoot":"","sources":["../../src/logic/validateField.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EAEL,WAAW,EACX,mBAAmB,EACnB,eAAe,EAKhB,MAAM,UAAU,CAAC;yBAsBI,CAAC,SAAS,WAAW,EACzC,OAAO,KAAK,EACZ,mBAAmB,eAAe,EAClC,YAAY,CAAC,EACb,0BAA0B,OAAO,EACjC,4BAA4B,OAAO,EACnC,eAAe,OAAO,KACrB,OAAO,CAAC,mBAAmB,CAAC;AAP/B,wBAqQE"}
|
|
@@ -643,10 +643,10 @@ var getValueAndMessage = (validationData) => isObject(validationData) && !isRege
|
|
|
643
643
|
message: '',
|
|
644
644
|
};
|
|
645
645
|
|
|
646
|
-
var validateField = async (field,
|
|
646
|
+
var validateField = async (field, skippedFieldNames, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
|
|
647
647
|
const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, } = field._f;
|
|
648
648
|
const inputValue = get(formValues, name);
|
|
649
|
-
if (!mount ||
|
|
649
|
+
if (!mount || skippedFieldNames.has(name)) {
|
|
650
650
|
return {};
|
|
651
651
|
}
|
|
652
652
|
const inputRef = refs ? refs[0] : ref;
|
|
@@ -835,6 +835,7 @@ const defaultOptions = {
|
|
|
835
835
|
mode: VALIDATION_MODE.onSubmit,
|
|
836
836
|
reValidateMode: VALIDATION_MODE.onChange,
|
|
837
837
|
shouldFocusError: true,
|
|
838
|
+
shouldSkipReadOnlyValidation: false,
|
|
838
839
|
};
|
|
839
840
|
function createFormControl(props = {}) {
|
|
840
841
|
let _options = {
|
|
@@ -879,6 +880,7 @@ function createFormControl(props = {}) {
|
|
|
879
880
|
let _names = {
|
|
880
881
|
mount: new Set(),
|
|
881
882
|
disabled: new Set(),
|
|
883
|
+
readonly: new Set(),
|
|
882
884
|
unMount: new Set(),
|
|
883
885
|
array: new Set(),
|
|
884
886
|
watch: new Set(),
|
|
@@ -1146,7 +1148,12 @@ function createFormControl(props = {}) {
|
|
|
1146
1148
|
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
|
1147
1149
|
_updateIsValidating([name], true);
|
|
1148
1150
|
}
|
|
1149
|
-
|
|
1151
|
+
// Combine disabled and readonly field names for validation skipping
|
|
1152
|
+
const skipValidationFields = new Set([
|
|
1153
|
+
..._names.disabled,
|
|
1154
|
+
..._names.readonly,
|
|
1155
|
+
]);
|
|
1156
|
+
const fieldError = await validateField(field, skipValidationFields, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
|
|
1150
1157
|
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
|
1151
1158
|
_updateIsValidating([name]);
|
|
1152
1159
|
}
|
|
@@ -1352,6 +1359,36 @@ function createFormControl(props = {}) {
|
|
|
1352
1359
|
}
|
|
1353
1360
|
return;
|
|
1354
1361
|
}
|
|
1362
|
+
// Check if field is readonly and should skip validation (only when flag is enabled)
|
|
1363
|
+
if (_options.shouldSkipReadOnlyValidation && target && target.readOnly) {
|
|
1364
|
+
// Add to readonly fields set for validation skipping
|
|
1365
|
+
_names.readonly.add(name);
|
|
1366
|
+
// For readonly fields, we still want to update the form values
|
|
1367
|
+
// but skip validation (similar to disabled fields behavior)
|
|
1368
|
+
const fieldValue = target.type
|
|
1369
|
+
? getFieldValue(field._f)
|
|
1370
|
+
: getEventValue(event);
|
|
1371
|
+
const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
|
|
1372
|
+
const isFocusEvent = event.type === EVENTS.FOCUS || event.type === EVENTS.FOCUS_IN;
|
|
1373
|
+
const watched = isWatched(name, _names, isBlurEvent || isFocusEvent);
|
|
1374
|
+
// Update form values but skip validation and error handling
|
|
1375
|
+
set(_formValues, name, fieldValue);
|
|
1376
|
+
// Update touch and dirty state
|
|
1377
|
+
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, isFocusEvent, !isBlurEvent);
|
|
1378
|
+
const shouldRender = !isEmptyObject(fieldState) || watched;
|
|
1379
|
+
!isBlurEvent &&
|
|
1380
|
+
_subjects.state.next({
|
|
1381
|
+
name,
|
|
1382
|
+
type: event.type,
|
|
1383
|
+
values: cloneObject(_formValues),
|
|
1384
|
+
});
|
|
1385
|
+
return (shouldRender &&
|
|
1386
|
+
_subjects.state.next({ name, ...(watched ? {} : fieldState) }));
|
|
1387
|
+
}
|
|
1388
|
+
else if (_options.shouldSkipReadOnlyValidation) {
|
|
1389
|
+
// Remove from readonly fields set if not readonly anymore (only when flag is enabled)
|
|
1390
|
+
_names.readonly.delete(name);
|
|
1391
|
+
}
|
|
1355
1392
|
let error;
|
|
1356
1393
|
let isValid;
|
|
1357
1394
|
const fieldValue = target.type
|
|
@@ -1411,7 +1448,12 @@ function createFormControl(props = {}) {
|
|
|
1411
1448
|
}
|
|
1412
1449
|
else {
|
|
1413
1450
|
_updateIsValidating([name], true);
|
|
1414
|
-
|
|
1451
|
+
// Combine disabled and readonly field names for validation skipping
|
|
1452
|
+
const skipValidationFields = new Set([
|
|
1453
|
+
..._names.disabled,
|
|
1454
|
+
..._names.readonly,
|
|
1455
|
+
]);
|
|
1456
|
+
error = (await validateField(field, skipValidationFields, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation, false))[name];
|
|
1415
1457
|
_updateIsValidating([name]);
|
|
1416
1458
|
_updateIsFieldValueUpdated(fieldValue);
|
|
1417
1459
|
if (isFieldValueUpdated) {
|
|
@@ -1662,6 +1704,13 @@ function createFormControl(props = {}) {
|
|
|
1662
1704
|
},
|
|
1663
1705
|
});
|
|
1664
1706
|
updateValidAndValue(name, false, undefined, fieldRef);
|
|
1707
|
+
// Check if field is readonly and should skip validation (only when flag is enabled)
|
|
1708
|
+
if (_options.shouldSkipReadOnlyValidation &&
|
|
1709
|
+
fieldRef &&
|
|
1710
|
+
'readOnly' in fieldRef &&
|
|
1711
|
+
fieldRef.readOnly) {
|
|
1712
|
+
_names.readonly.add(name);
|
|
1713
|
+
}
|
|
1665
1714
|
}
|
|
1666
1715
|
else {
|
|
1667
1716
|
field = get(_fields, name, {});
|
|
@@ -1862,6 +1911,7 @@ function createFormControl(props = {}) {
|
|
|
1862
1911
|
unMount: new Set(),
|
|
1863
1912
|
array: new Set(),
|
|
1864
1913
|
disabled: new Set(),
|
|
1914
|
+
readonly: new Set(),
|
|
1865
1915
|
watch: new Set(),
|
|
1866
1916
|
watchAll: false,
|
|
1867
1917
|
focus: '',
|
|
@@ -1961,6 +2011,28 @@ function createFormControl(props = {}) {
|
|
|
1961
2011
|
});
|
|
1962
2012
|
}
|
|
1963
2013
|
};
|
|
2014
|
+
const _updateReadonlyFieldTracking = () => {
|
|
2015
|
+
// Re-evaluate all registered fields and update readonly tracking
|
|
2016
|
+
// based on current shouldSkipReadOnlyValidation flag and field readonly state
|
|
2017
|
+
Object.keys(_fields).forEach((fieldName) => {
|
|
2018
|
+
const field = get(_fields, fieldName);
|
|
2019
|
+
if (field && field._f) {
|
|
2020
|
+
// Get the actual DOM element reference
|
|
2021
|
+
const fieldRef = field._f.refs ? field._f.refs[0] : field._f.ref;
|
|
2022
|
+
if (fieldRef && 'readOnly' in fieldRef) {
|
|
2023
|
+
const isFieldReadonly = Boolean(fieldRef.readOnly);
|
|
2024
|
+
const shouldTrackAsReadonly = _options.shouldSkipReadOnlyValidation && isFieldReadonly;
|
|
2025
|
+
// Update readonly tracking set
|
|
2026
|
+
if (shouldTrackAsReadonly) {
|
|
2027
|
+
_names.readonly.add(fieldName);
|
|
2028
|
+
}
|
|
2029
|
+
else {
|
|
2030
|
+
_names.readonly.delete(fieldName);
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
2035
|
+
};
|
|
1964
2036
|
const setMetadata = (metadata) => {
|
|
1965
2037
|
let _metadata;
|
|
1966
2038
|
if (!metadata) {
|
|
@@ -2005,6 +2077,7 @@ function createFormControl(props = {}) {
|
|
|
2005
2077
|
_removeUnmounted,
|
|
2006
2078
|
_disableForm,
|
|
2007
2079
|
_updateIsLoading,
|
|
2080
|
+
_updateReadonlyFieldTracking,
|
|
2008
2081
|
_subjects,
|
|
2009
2082
|
_proxyFormState,
|
|
2010
2083
|
get _fields() {
|