diff --git a/src/components/formio/textfield.tsx b/src/components/formio/textfield.tsx index 082a2103..4b08825d 100644 --- a/src/components/formio/textfield.tsx +++ b/src/components/formio/textfield.tsx @@ -1,6 +1,6 @@ import clsx from 'clsx'; import {Field, useFormikContext} from 'formik'; -import {useContext, useRef} from 'react'; +import {useContext, useEffect, useRef} from 'react'; import {RenderContext} from '@/context'; import CharCount from '@/utils/charcount'; @@ -35,7 +35,7 @@ export const TextField: React.FC { - const {getFieldProps, getFieldMeta} = useFormikContext(); + const {getFieldProps, getFieldMeta, setFieldValue} = useFormikContext(); const {value, onChange: formikOnChange} = getFieldProps(name); const {touched} = getFieldMeta(name); const {errors, hasErrors} = useValidationErrors(name); @@ -48,6 +48,13 @@ export const TextField: React.FC { + if (value === undefined || value === null) { + // Make sure value is valid + setFieldValue(name, ''); + } + }, [value]); + // XXX: this is only accepted in the form builder to get to (close to) vanilla form // builder feature parity - setting the value with mask placeholders is bad for // accessibility.