validate required on submit not blur

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