File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 1
1
import clsx from 'clsx' ;
2
2
import { Field , useFormikContext } from 'formik' ;
3
- import { useContext , useRef } from 'react' ;
3
+ import { useContext , useEffect , useRef } from 'react' ;
4
4
5
5
import { RenderContext } from '@/context' ;
6
6
import CharCount from '@/utils/charcount' ;
@@ -35,7 +35,7 @@ export const TextField: React.FC<JSX.IntrinsicElements['input'] & TextFieldProps
35
35
childrenAfterField,
36
36
...props
37
37
} ) => {
38
- const { getFieldProps, getFieldMeta} = useFormikContext ( ) ;
38
+ const { getFieldProps, getFieldMeta, setFieldValue } = useFormikContext ( ) ;
39
39
const { value, onChange : formikOnChange } = getFieldProps < string | undefined > ( name ) ;
40
40
const { touched} = getFieldMeta < string | undefined > ( name ) ;
41
41
const { errors, hasErrors} = useValidationErrors ( name ) ;
@@ -48,6 +48,13 @@ export const TextField: React.FC<JSX.IntrinsicElements['input'] & TextFieldProps
48
48
props = { ...props , value : '' } ;
49
49
}
50
50
51
+ useEffect ( ( ) => {
52
+ if ( value === undefined || value === null ) {
53
+ // Make sure value is valid
54
+ setFieldValue ( name , '' ) ;
55
+ }
56
+ } , [ value ] ) ;
57
+
51
58
// XXX: this is only accepted in the form builder to get to (close to) vanilla form
52
59
// builder feature parity - setting the value with mask placeholders is bad for
53
60
// accessibility.
You can’t perform that action at this time.
0 commit comments