Skip to content

Commit

Permalink
Fix display of warnings for forms that use both form-level and field-…
Browse files Browse the repository at this point in the history
…level validation (#3263)
  • Loading branch information
juliawegmayr authored Feb 19, 2025
1 parent 457c62d commit faa54eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/famous-pianos-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/admin": patch
---

Fix display of warnings for forms that use both form-level and field-level validation
10 changes: 9 additions & 1 deletion packages/admin/admin/src/FinalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ export function FinalForm<FormValues = AnyObject, InitialFormValues = Partial<Fo

const registeredFields = formRenderProps.form.getRegisteredFields();

const formLevelWarnings = useRef<Record<string, string | undefined>>({});

useEffect(() => {
if (validateWarning) {
const validate = async () => {
Expand All @@ -177,11 +179,17 @@ export function FinalForm<FormValues = AnyObject, InitialFormValues = Partial<Fo

if (!validationWarnings) {
registeredFields.forEach((fieldName) => {
setFieldData(fieldName, { warning: undefined });
const hasFormLevelWarning = Boolean(formLevelWarnings.current[fieldName]);
if (hasFormLevelWarning) {
setFieldData(fieldName, { warning: undefined });
}
});
formLevelWarnings.current = {};
return;
}

formLevelWarnings.current = validationWarnings;

Object.entries(validationWarnings).forEach(([fieldName, warning]) => {
setFieldData(fieldName, { warning });
});
Expand Down

0 comments on commit faa54eb

Please sign in to comment.