File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 51
51
"type" : " (isValid: boolean) => void" ,
52
52
"description" : " Callback for when field validity has changed"
53
53
},
54
+ {
55
+ "name" : " onValidationFailed" ,
56
+ "type" : " (failedValidatorIndex: number) => void" ,
57
+ "description" : " Callback for when field validated and failed"
58
+ },
54
59
{
55
60
"name" : " fieldStyle" ,
56
61
"type" : " ViewStyle | (context: FieldContextType, props) => ViewStyle" ,
Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ export interface FieldStateProps extends InputProps {
36
36
validateOnStart ?: boolean ;
37
37
validateOnChange ?: boolean ;
38
38
validateOnBlur ?: boolean ;
39
+ /**
40
+ * Callback for when field validated and failed
41
+ */
42
+ onValidationFailed ?: ( failedValidatorIndex : number ) => void ;
39
43
/**
40
44
* A single or multiple validator. Can be a string (required, email) or custom function.
41
45
*/
@@ -203,6 +207,10 @@ export type TextFieldProps = MarginModifiers &
203
207
* Should validate when losing focus of TextField
204
208
*/
205
209
validateOnBlur ?: boolean ;
210
+ /**
211
+ * Callback for when field validated and failed
212
+ */
213
+ onValidationFailed ?: ( failedValidatorIndex : number ) => void ;
206
214
/**
207
215
* Callback for when field validity has changed
208
216
*/
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ export default function useFieldState({
11
11
validateOnBlur,
12
12
validateOnChange,
13
13
validateOnStart,
14
+ onValidationFailed,
14
15
onChangeValidity,
15
16
...props
16
17
} : FieldStateProps ) {
@@ -68,9 +69,13 @@ export default function useFieldState({
68
69
setIsValid ( _isValid ) ;
69
70
setFailingValidatorIndex ( _failingValidatorIndex ) ;
70
71
72
+ if ( ! _isValid && ! _ . isUndefined ( _failingValidatorIndex ) ) {
73
+ onValidationFailed ?.( _failingValidatorIndex ) ;
74
+ }
75
+
71
76
return _isValid ;
72
77
} ,
73
- [ value , validate ] ) ;
78
+ [ value , validate , onValidationFailed ] ) ;
74
79
75
80
const onFocus = useCallback ( ( ...args : any ) => {
76
81
setIsFocused ( true ) ;
You can’t perform that action at this time.
0 commit comments