fix: improve error handling for required fields in Form component
This commit is contained in:
parent
e614c4b82c
commit
af41495643
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue