fix: ensures failed conditions send path to form
This commit is contained in:
@@ -119,6 +119,7 @@ function fieldReducer(state: Fields, action): Fields {
|
||||
initialValue: action.initialValue,
|
||||
stringify: action.stringify,
|
||||
validate: action.validate,
|
||||
condition: action.condition,
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -33,18 +33,19 @@ const withCondition = <P extends Record<string, unknown>>(Field: React.Component
|
||||
const { getData, getSiblingData, getField, dispatchFields } = useWatchForm();
|
||||
|
||||
const data = getData();
|
||||
const field = getField(path);
|
||||
const siblingData = getSiblingData(path);
|
||||
const passesCondition = condition ? condition(data, siblingData) : true;
|
||||
|
||||
useEffect(() => {
|
||||
if (!passesCondition) {
|
||||
const field = getField(path);
|
||||
dispatchFields({
|
||||
...field,
|
||||
path,
|
||||
valid: true,
|
||||
});
|
||||
}
|
||||
}, [passesCondition, field, dispatchFields]);
|
||||
}, [passesCondition, getField, dispatchFields, path]);
|
||||
|
||||
if (passesCondition) {
|
||||
return <Field {...props} />;
|
||||
|
||||
Reference in New Issue
Block a user