@bombillazo/rhf-plus 7.62.0-plus.5 → 7.62.0-plus.6
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 +2 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +53 -5
- 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/react-server.esm.mjs +49 -5
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/form.d.ts +4 -0
- package/dist/types/form.d.ts.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/dist/useFormState.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -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;AAuDlB,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,
|
|
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;AAuDlB,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,CAipDA"}
|
|
@@ -845,6 +845,8 @@ function createFormControl(props = {}) {
|
|
|
845
845
|
let _formState = {
|
|
846
846
|
submitCount: 0,
|
|
847
847
|
isDirty: false,
|
|
848
|
+
isDirtySinceSubmit: false,
|
|
849
|
+
hasBeenSubmitted: false,
|
|
848
850
|
isReady: false,
|
|
849
851
|
isLoading: _internalLoading,
|
|
850
852
|
isValidating: false,
|
|
@@ -885,6 +887,8 @@ function createFormControl(props = {}) {
|
|
|
885
887
|
let timer = 0;
|
|
886
888
|
const _proxyFormState = {
|
|
887
889
|
isDirty: false,
|
|
890
|
+
isDirtySinceSubmit: false,
|
|
891
|
+
hasBeenSubmitted: false,
|
|
888
892
|
dirtyFields: false,
|
|
889
893
|
validatingFields: false,
|
|
890
894
|
touchedFields: false,
|
|
@@ -902,6 +906,8 @@ function createFormControl(props = {}) {
|
|
|
902
906
|
};
|
|
903
907
|
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
|
904
908
|
const id = createId(props.id);
|
|
909
|
+
// Track if form was ever submitted (persists through resets)
|
|
910
|
+
let _hasBeenSubmitted = false;
|
|
905
911
|
const debounce = (callback) => (wait) => {
|
|
906
912
|
clearTimeout(timer);
|
|
907
913
|
timer = setTimeout(callback, wait);
|
|
@@ -1025,6 +1031,20 @@ function createFormControl(props = {}) {
|
|
|
1025
1031
|
_proxySubscribeFormState.dirtyFields) &&
|
|
1026
1032
|
isPreviousDirty !== !isCurrentFieldPristine);
|
|
1027
1033
|
}
|
|
1034
|
+
// Set isDirtySinceSubmit to true if form was ever submitted and a field value is being changed
|
|
1035
|
+
// For change events (not blur/focus), always set if form was ever submitted
|
|
1036
|
+
// shouldDirty is true for onChange events, false for blur
|
|
1037
|
+
if ((_formState.isSubmitted || _hasBeenSubmitted) &&
|
|
1038
|
+
!_formState.isDirtySinceSubmit &&
|
|
1039
|
+
!isBlurEvent &&
|
|
1040
|
+
!isFocusEvent &&
|
|
1041
|
+
shouldDirty) {
|
|
1042
|
+
_formState.isDirtySinceSubmit = output.isDirtySinceSubmit = true;
|
|
1043
|
+
shouldUpdateField =
|
|
1044
|
+
shouldUpdateField ||
|
|
1045
|
+
!!(_proxyFormState.isDirtySinceSubmit ||
|
|
1046
|
+
_proxySubscribeFormState.isDirtySinceSubmit);
|
|
1047
|
+
}
|
|
1028
1048
|
if (isBlurEvent) {
|
|
1029
1049
|
const isPreviousFieldTouched = get(_formState.touchedFields, name);
|
|
1030
1050
|
if (!isPreviousFieldTouched) {
|
|
@@ -1220,9 +1240,15 @@ function createFormControl(props = {}) {
|
|
|
1220
1240
|
}
|
|
1221
1241
|
}
|
|
1222
1242
|
}
|
|
1223
|
-
(
|
|
1243
|
+
const isSubmittedAndDirty = (_formState.isSubmitted || _hasBeenSubmitted) &&
|
|
1244
|
+
!deepEqual(get(_defaultValues, name), fieldValue);
|
|
1245
|
+
// If the form was submitted, track value changes for isDirtySinceSubmit
|
|
1246
|
+
// only when the value actually differs from the default value,
|
|
1247
|
+
// even if shouldDirty is not explicitly set
|
|
1248
|
+
const shouldTrackChange = options.shouldDirty || options.shouldTouch || isSubmittedAndDirty;
|
|
1249
|
+
shouldTrackChange &&
|
|
1224
1250
|
updateTouchAndDirty(name, fieldValue, options.shouldTouch, false, // isFocusEvent - not applicable for setValue
|
|
1225
|
-
options.shouldDirty, true);
|
|
1251
|
+
options.shouldDirty || isSubmittedAndDirty, true);
|
|
1226
1252
|
options.shouldValidate && trigger(name);
|
|
1227
1253
|
};
|
|
1228
1254
|
const setValues = (name, value, options) => {
|
|
@@ -1254,12 +1280,25 @@ function createFormControl(props = {}) {
|
|
|
1254
1280
|
if ((_proxyFormState.isDirty ||
|
|
1255
1281
|
_proxyFormState.dirtyFields ||
|
|
1256
1282
|
_proxySubscribeFormState.isDirty ||
|
|
1257
|
-
_proxySubscribeFormState.dirtyFields
|
|
1283
|
+
_proxySubscribeFormState.dirtyFields ||
|
|
1284
|
+
_proxyFormState.isDirtySinceSubmit ||
|
|
1285
|
+
_proxySubscribeFormState.isDirtySinceSubmit) &&
|
|
1258
1286
|
options.shouldDirty) {
|
|
1259
1287
|
_subjects.state.next({
|
|
1260
1288
|
name,
|
|
1261
1289
|
dirtyFields: getDirtyFields(_defaultValues, _formValues),
|
|
1262
1290
|
isDirty: _getDirty(name, cloneValue),
|
|
1291
|
+
...((_formState.isSubmitted || _hasBeenSubmitted) &&
|
|
1292
|
+
!_formState.isDirtySinceSubmit
|
|
1293
|
+
? { isDirtySinceSubmit: true }
|
|
1294
|
+
: {}),
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
else if ((_formState.isSubmitted || _hasBeenSubmitted) &&
|
|
1298
|
+
!_formState.isDirtySinceSubmit) {
|
|
1299
|
+
_subjects.state.next({
|
|
1300
|
+
name,
|
|
1301
|
+
isDirtySinceSubmit: true,
|
|
1263
1302
|
});
|
|
1264
1303
|
}
|
|
1265
1304
|
}
|
|
@@ -1336,7 +1375,7 @@ function createFormControl(props = {}) {
|
|
|
1336
1375
|
else if (field._f.onChange) {
|
|
1337
1376
|
field._f.onChange(event);
|
|
1338
1377
|
}
|
|
1339
|
-
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, isFocusEvent);
|
|
1378
|
+
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, isFocusEvent, !isBlurEvent);
|
|
1340
1379
|
const shouldRender = !isEmptyObject(fieldState) || watched;
|
|
1341
1380
|
!isBlurEvent &&
|
|
1342
1381
|
_subjects.state.next({
|
|
@@ -1720,11 +1759,14 @@ function createFormControl(props = {}) {
|
|
|
1720
1759
|
_focusError();
|
|
1721
1760
|
setTimeout(_focusError);
|
|
1722
1761
|
}
|
|
1762
|
+
_hasBeenSubmitted = true; // Mark that form was submitted at least once
|
|
1723
1763
|
_subjects.state.next({
|
|
1724
1764
|
isSubmitted: true,
|
|
1725
1765
|
isSubmitting: false,
|
|
1726
1766
|
isSubmitSuccessful: isEmptyObject(_formState.errors) && !onValidError,
|
|
1727
1767
|
submitCount: _formState.submitCount + 1,
|
|
1768
|
+
isDirtySinceSubmit: false,
|
|
1769
|
+
hasBeenSubmitted: _hasBeenSubmitted,
|
|
1728
1770
|
errors: _formState.errors,
|
|
1729
1771
|
});
|
|
1730
1772
|
if (onValidError) {
|
|
@@ -1787,7 +1829,7 @@ function createFormControl(props = {}) {
|
|
|
1787
1829
|
if (isHTMLElement(fieldReference)) {
|
|
1788
1830
|
const form = fieldReference.closest('form');
|
|
1789
1831
|
if (form) {
|
|
1790
|
-
|
|
1832
|
+
HTMLFormElement.prototype.reset.call(form);
|
|
1791
1833
|
break;
|
|
1792
1834
|
}
|
|
1793
1835
|
}
|
|
@@ -1839,6 +1881,8 @@ function createFormControl(props = {}) {
|
|
|
1839
1881
|
? _formState.isDirty
|
|
1840
1882
|
: !!(keepStateOptions.keepDefaultValues &&
|
|
1841
1883
|
!deepEqual(formValues, _defaultValues)),
|
|
1884
|
+
isDirtySinceSubmit: false,
|
|
1885
|
+
hasBeenSubmitted: _hasBeenSubmitted, // Persist the hasBeenSubmitted flag
|
|
1842
1886
|
isSubmitted: keepStateOptions.keepIsSubmitted
|
|
1843
1887
|
? _formState.isSubmitted
|
|
1844
1888
|
: false,
|