validate required on submit not blur

This commit is contained in:
2024-10-07 11:21:16 +01:00
parent 934342b8e3
commit a2ff59f32d
+18 -15
View File
@@ -2,7 +2,7 @@ import useTranslation from "next-translate/useTranslation";
import Link from "next/link";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { Field, reduxForm } from "redux-form";
import { Field, reduxForm, SubmissionError } from "redux-form";
import { sendGAEvent } from "@next/third-parties/google";
const required = (errorMsg) => (value) =>
@@ -84,15 +84,23 @@ let CaseSearch = (props) => {
// };
const onHandleSubmit = (values) => {
//spinnerState();
router.push({
pathname:
router.locale == "cy"
? "/fymhorth/canlyniadauchwilio"
: "/myportal/searchresults",
query: { q: values.basicSearch },
shallow: true,
});
if (Object.keys(values).length === 0) {
console.log(props.error);
throw new SubmissionError({
basicSearch: t("myportal:searchcases-validation-required"),
_error: "required",
});
} else {
router.push({
pathname:
router.locale == "cy"
? "/fymhorth/canlyniadauchwilio"
: "/myportal/searchresults",
query: { q: values.basicSearch },
shallow: true,
});
}
};
return (
@@ -106,11 +114,6 @@ let CaseSearch = (props) => {
<Field
validate={[
required(
t(
"myportal:searchcases-validation-required"
)
),
minLength(
t(
"myportal:searchcases-validation-minlength"