validate required on submit not blur
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user