@react-stately/form
Advanced tools
Comparing version
@@ -0,3 +1,3 @@ | ||
import { Context } from "react"; | ||
import { Validation, ValidationErrors, ValidationResult } from "@react-types/shared"; | ||
import { Context } from "react"; | ||
export const VALID_VALIDITY_STATE: ValidityState; | ||
@@ -10,3 +10,3 @@ export const DEFAULT_VALIDATION_RESULT: ValidationResult; | ||
name?: string | string[]; | ||
value: T; | ||
value: T | null; | ||
} | ||
@@ -13,0 +13,0 @@ export interface FormValidationState { |
@@ -76,7 +76,11 @@ var $kFCAu$react = require("react"); | ||
// Perform custom client side validation. | ||
let clientError = (0, $kFCAu$react.useMemo)(()=>$5d10129a174740d4$var$getValidationResult($5d10129a174740d4$var$runValidate(validate, value)), [ | ||
let clientError = (0, $kFCAu$react.useMemo)(()=>{ | ||
if (!validate || value == null) return null; | ||
let validateErrors = $5d10129a174740d4$var$runValidate(validate, value); | ||
return $5d10129a174740d4$var$getValidationResult(validateErrors); | ||
}, [ | ||
validate, | ||
value | ||
]); | ||
if (builtinValidation === null || builtinValidation === void 0 ? void 0 : builtinValidation.validationDetails.valid) builtinValidation = null; | ||
if (builtinValidation === null || builtinValidation === void 0 ? void 0 : builtinValidation.validationDetails.valid) builtinValidation = undefined; | ||
// Get relevant server errors from the form. | ||
@@ -173,3 +177,3 @@ let serverErrors = (0, $kFCAu$react.useContext)($5d10129a174740d4$export$571b5131b7e65c11); | ||
if (a === b) return true; | ||
return a && b && a.isInvalid === b.isInvalid && a.validationErrors.length === b.validationErrors.length && a.validationErrors.every((a, i)=>a === b.validationErrors[i]) && Object.entries(a.validationDetails).every(([k, v])=>b.validationDetails[k] === v); | ||
return !!a && !!b && a.isInvalid === b.isInvalid && a.validationErrors.length === b.validationErrors.length && a.validationErrors.every((a, i)=>a === b.validationErrors[i]) && Object.entries(a.validationDetails).every(([k, v])=>b.validationDetails[k] === v); | ||
} | ||
@@ -176,0 +180,0 @@ function $5d10129a174740d4$export$75ee7c75d68f5b0e(...results) { |
@@ -65,7 +65,11 @@ import {createContext as $69F46$createContext, useMemo as $69F46$useMemo, useContext as $69F46$useContext, useState as $69F46$useState, useRef as $69F46$useRef, useEffect as $69F46$useEffect} from "react"; | ||
// Perform custom client side validation. | ||
let clientError = (0, $69F46$useMemo)(()=>$e5be200c675c3b3a$var$getValidationResult($e5be200c675c3b3a$var$runValidate(validate, value)), [ | ||
let clientError = (0, $69F46$useMemo)(()=>{ | ||
if (!validate || value == null) return null; | ||
let validateErrors = $e5be200c675c3b3a$var$runValidate(validate, value); | ||
return $e5be200c675c3b3a$var$getValidationResult(validateErrors); | ||
}, [ | ||
validate, | ||
value | ||
]); | ||
if (builtinValidation === null || builtinValidation === void 0 ? void 0 : builtinValidation.validationDetails.valid) builtinValidation = null; | ||
if (builtinValidation === null || builtinValidation === void 0 ? void 0 : builtinValidation.validationDetails.valid) builtinValidation = undefined; | ||
// Get relevant server errors from the form. | ||
@@ -162,3 +166,3 @@ let serverErrors = (0, $69F46$useContext)($e5be200c675c3b3a$export$571b5131b7e65c11); | ||
if (a === b) return true; | ||
return a && b && a.isInvalid === b.isInvalid && a.validationErrors.length === b.validationErrors.length && a.validationErrors.every((a, i)=>a === b.validationErrors[i]) && Object.entries(a.validationDetails).every(([k, v])=>b.validationDetails[k] === v); | ||
return !!a && !!b && a.isInvalid === b.isInvalid && a.validationErrors.length === b.validationErrors.length && a.validationErrors.every((a, i)=>a === b.validationErrors[i]) && Object.entries(a.validationDetails).every(([k, v])=>b.validationDetails[k] === v); | ||
} | ||
@@ -165,0 +169,0 @@ function $e5be200c675c3b3a$export$75ee7c75d68f5b0e(...results) { |
{ | ||
"name": "@react-stately/form", | ||
"version": "3.0.0-nightly-8ab4f20de-240913", | ||
"version": "3.0.0-nightly-8c5b7a011-250827", | ||
"description": "Spectrum UI components in React", | ||
@@ -10,3 +10,7 @@ "license": "Apache-2.0", | ||
"exports": { | ||
"types": "./dist/types.d.ts", | ||
"source": "./src/index.ts", | ||
"types": [ | ||
"./dist/types.d.ts", | ||
"./src/index.ts" | ||
], | ||
"import": "./dist/import.mjs", | ||
@@ -26,12 +30,11 @@ "require": "./dist/main.js" | ||
"dependencies": { | ||
"@react-types/shared": "^3.0.0-nightly-8ab4f20de-240913", | ||
"@react-types/shared": "3.0.0-nightly-8c5b7a011-250827", | ||
"@swc/helpers": "^0.5.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0" | ||
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"stableVersion": "3.0.5" | ||
} | ||
} |
@@ -13,3 +13,3 @@ /* | ||
import {createContext, useContext, useEffect, useMemo, useRef, useState} from 'react'; | ||
import {Context, createContext, useContext, useEffect, useMemo, useRef, useState} from 'react'; | ||
import {Validation, ValidationErrors, ValidationFunction, ValidationResult} from '@react-types/shared'; | ||
@@ -43,5 +43,5 @@ | ||
export const FormValidationContext = createContext<ValidationErrors>({}); | ||
export const FormValidationContext: Context<ValidationErrors> = createContext<ValidationErrors>({}); | ||
export const privateValidationStateProp = '__formValidationState' + Date.now(); | ||
export const privateValidationStateProp: string = '__formValidationState' + Date.now(); | ||
@@ -51,3 +51,3 @@ interface FormValidationProps<T> extends Validation<T> { | ||
name?: string | string[], | ||
value: T | ||
value: T | null | ||
} | ||
@@ -95,6 +95,12 @@ | ||
// Perform custom client side validation. | ||
let clientError: ValidationResult | null = useMemo(() => getValidationResult(runValidate(validate, value)), [validate, value]); | ||
let clientError: ValidationResult | null = useMemo(() => { | ||
if (!validate || value == null) { | ||
return null; | ||
} | ||
let validateErrors = runValidate(validate, value); | ||
return getValidationResult(validateErrors); | ||
}, [validate, value]); | ||
if (builtinValidation?.validationDetails.valid) { | ||
builtinValidation = null; | ||
builtinValidation = undefined; | ||
} | ||
@@ -224,3 +230,3 @@ | ||
return a && b | ||
return !!a && !!b | ||
&& a.isInvalid === b.isInvalid | ||
@@ -227,0 +233,0 @@ && a.validationErrors.length === b.validationErrors.length |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
78070
1.58%891
2.06%+ Added
- Removed