@tanstack/form-core 1.6.2 → 1.7.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/cjs/FieldApi.cjs +63 -36
- package/dist/cjs/FieldApi.cjs.map +1 -1
- package/dist/cjs/FieldApi.d.cts +5 -1
- package/dist/cjs/FormApi.cjs +85 -48
- package/dist/cjs/FormApi.cjs.map +1 -1
- package/dist/cjs/FormApi.d.cts +22 -8
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/metaHelper.cjs +2 -1
- package/dist/cjs/metaHelper.cjs.map +1 -1
- package/dist/cjs/types.d.cts +10 -0
- package/dist/cjs/utils.cjs +30 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +24 -1
- package/dist/esm/FieldApi.d.ts +5 -1
- package/dist/esm/FieldApi.js +64 -37
- package/dist/esm/FieldApi.js.map +1 -1
- package/dist/esm/FormApi.d.ts +22 -8
- package/dist/esm/FormApi.js +86 -49
- package/dist/esm/FormApi.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/metaHelper.js +2 -1
- package/dist/esm/metaHelper.js.map +1 -1
- package/dist/esm/types.d.ts +10 -0
- package/dist/esm/utils.d.ts +24 -1
- package/dist/esm/utils.js +30 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/FieldApi.ts +76 -32
- package/src/FormApi.ts +191 -70
- package/src/metaHelper.ts +1 -0
- package/src/types.ts +11 -0
- package/src/utils.ts +68 -1
package/src/types.ts
CHANGED
|
@@ -40,6 +40,17 @@ export type ValidationErrorMap<
|
|
|
40
40
|
onServer?: TOnServerReturn
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @private allows tracking the source of the errors in the error map
|
|
45
|
+
*/
|
|
46
|
+
export type ValidationErrorMapSource = {
|
|
47
|
+
onMount?: ValidationSource
|
|
48
|
+
onChange?: ValidationSource
|
|
49
|
+
onBlur?: ValidationSource
|
|
50
|
+
onSubmit?: ValidationSource
|
|
51
|
+
onServer?: ValidationSource
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
/**
|
|
44
55
|
* @private
|
|
45
56
|
*/
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
GlobalFormValidationError,
|
|
3
|
+
ValidationCause,
|
|
4
|
+
ValidationError,
|
|
5
|
+
ValidationSource,
|
|
6
|
+
} from './types'
|
|
2
7
|
import type { FormValidators } from './FormApi'
|
|
3
8
|
import type { AnyFieldMeta, FieldValidators } from './FieldApi'
|
|
4
9
|
|
|
@@ -376,3 +381,65 @@ export function shallow<T>(objA: T, objB: T) {
|
|
|
376
381
|
}
|
|
377
382
|
return true
|
|
378
383
|
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Determines the logic for determining the error source and value to set on the field meta within the form level sync/async validation.
|
|
387
|
+
* @private
|
|
388
|
+
*/
|
|
389
|
+
export const determineFormLevelErrorSourceAndValue = ({
|
|
390
|
+
newFormValidatorError,
|
|
391
|
+
isPreviousErrorFromFormValidator,
|
|
392
|
+
previousErrorValue,
|
|
393
|
+
}: {
|
|
394
|
+
newFormValidatorError: ValidationError
|
|
395
|
+
isPreviousErrorFromFormValidator: boolean
|
|
396
|
+
previousErrorValue: ValidationError
|
|
397
|
+
}): {
|
|
398
|
+
newErrorValue: ValidationError
|
|
399
|
+
newSource: ValidationSource | undefined
|
|
400
|
+
} => {
|
|
401
|
+
// All falsy values are not considered errors
|
|
402
|
+
if (newFormValidatorError) {
|
|
403
|
+
return { newErrorValue: newFormValidatorError, newSource: 'form' }
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Clears form level error since it's now stale
|
|
407
|
+
if (isPreviousErrorFromFormValidator) {
|
|
408
|
+
return { newErrorValue: undefined, newSource: undefined }
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// At this point, we have a preivous error which must have been set by the field validator, keep as is
|
|
412
|
+
if (previousErrorValue) {
|
|
413
|
+
return { newErrorValue: previousErrorValue, newSource: 'field' }
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// No new or previous error, clear the error
|
|
417
|
+
return { newErrorValue: undefined, newSource: undefined }
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Determines the logic for determining the error source and value to set on the field meta within the field level sync/async validation.
|
|
422
|
+
* @private
|
|
423
|
+
*/
|
|
424
|
+
export const determineFieldLevelErrorSourceAndValue = ({
|
|
425
|
+
formLevelError,
|
|
426
|
+
fieldLevelError,
|
|
427
|
+
}: {
|
|
428
|
+
formLevelError: ValidationError
|
|
429
|
+
fieldLevelError: ValidationError
|
|
430
|
+
}): {
|
|
431
|
+
newErrorValue: ValidationError
|
|
432
|
+
newSource: ValidationSource | undefined
|
|
433
|
+
} => {
|
|
434
|
+
// At field level, we prioritize the field level error
|
|
435
|
+
if (fieldLevelError) {
|
|
436
|
+
return { newErrorValue: fieldLevelError, newSource: 'field' }
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// If there is no field level error, and there is a form level error, we set the form level error
|
|
440
|
+
if (formLevelError) {
|
|
441
|
+
return { newErrorValue: formLevelError, newSource: 'form' }
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return { newErrorValue: undefined, newSource: undefined }
|
|
445
|
+
}
|