Prerequisites
What theme are you using?
core
Version
6.x
Current Behavior
Validation error is shown when submitting a form for a field when it is being cleared, because it is set to null by ArrayField onChange.
Expected Behavior
No validation error is shown when submitting.
Steps To Reproduce
- Visit this playground link
- Clear the age field for the 1st array item.
- Click submit. Notice that the error message "must be number" appears for the age field.
Environment
Anything else?
Here's my proposed fix in ArrayField.tsx:
const handleChange = useCallback(
(value: any, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
const isArrayItemChange = typeof path.at(-1) === "number";
onChange(
// We need to treat undefined items as nulls to have validation.
// See https://github.com/tdegrunt/jsonschema/issues/206
// Only set to null for array items, and not for object properties within array items.
isArrayItemChange && value === undefined ? null : value,
path,
newErrorSchema as ErrorSchema<T[]>,
id,
);
},
[onChange],
);
Prerequisites
What theme are you using?
core
Version
6.x
Current Behavior
Validation error is shown when submitting a form for a field when it is being cleared, because it is set to null by ArrayField onChange.
Expected Behavior
No validation error is shown when submitting.
Steps To Reproduce
Environment
Anything else?
Here's my proposed fix in ArrayField.tsx: