fix: improve error handling for required fields in Form component

This commit is contained in:
faisolavolut 2025-02-27 14:23:58 +07:00
parent e614c4b82c
commit af41495643
1 changed files with 69 additions and 63 deletions

View File

@ -76,6 +76,7 @@ export const Form: React.FC<any> = ({
console.error("Error processing date fields:", ex);
}
if (mode !== "view") {
const fieldRequired = Object.values(fieldDate).filter(
(field: any) => field?.required || field?.type === "table"
);
@ -107,13 +108,17 @@ export const Form: React.FC<any> = ({
"multi-async",
].includes(typeSub)
) {
if (!Array.isArray(get(local.data, keys)) || !val?.length) {
if (
!Array.isArray(get(local.data, keys)) ||
!val?.length
) {
errorChilds[subField.name] =
"This field requires at least one item.";
isError = true;
}
} else if (!val) {
errorChilds[subField.name] = "Please fill out this field.";
errorChilds[subField.name] =
"Please fill out this field.";
isError = true;
}
@ -150,6 +155,7 @@ export const Form: React.FC<any> = ({
}
});
}
}
local.error = error;
local.render();