enforces that changing a locale clears form state
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useContext, useCallback, useEffect } from 'react';
|
||||
import FormContext from '../Form/Context';
|
||||
import { useLocale } from '../../utilities/Locale';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
@@ -12,6 +13,7 @@ const useFieldType = (options) => {
|
||||
validate,
|
||||
} = options;
|
||||
|
||||
const locale = useLocale();
|
||||
const formContext = useContext(FormContext);
|
||||
const { dispatchFields, submitted, processing } = formContext;
|
||||
const mountValue = formContext.fields[name]?.value || null;
|
||||
@@ -42,6 +44,10 @@ const useFieldType = (options) => {
|
||||
if (defaultValue != null) sendField(defaultValue);
|
||||
}, [defaultValue, sendField]);
|
||||
|
||||
useEffect(() => {
|
||||
sendField(null);
|
||||
}, [locale, sendField]);
|
||||
|
||||
const valid = formContext.fields[name] ? formContext.fields[name].valid : true;
|
||||
const showError = valid === false && formContext.submitted;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user