add validation
This commit is contained in:
parent
ca653967fa
commit
34d8a821b0
|
|
@ -18,7 +18,7 @@ const EditLazyModal = React.lazy(() => import("./EditLaTexModal"));
|
||||||
const LaTeXInputMemo: React.FC<any> = React.memo(({ field ,form, label, ...props }) => {
|
const LaTeXInputMemo: React.FC<any> = React.memo(({ field ,form, label, ...props }) => {
|
||||||
const { name ,value} = field;
|
const { name ,value} = field;
|
||||||
|
|
||||||
const { setFieldValue } = form;
|
const { setFieldValue ,touched ,errors } = form;
|
||||||
|
|
||||||
const { ShowLatexOption, Success } = useObjectToEdit();
|
const { ShowLatexOption, Success } = useObjectToEdit();
|
||||||
const [showPreview, setShowPreview] = useState(false);
|
const [showPreview, setShowPreview] = useState(false);
|
||||||
|
|
@ -58,11 +58,12 @@ const LaTeXInputMemo: React.FC<any> = React.memo(({ field ,form, label, ...prop
|
||||||
}
|
}
|
||||||
}, [Success])
|
}, [Success])
|
||||||
|
|
||||||
|
const isError = !!touched?.[name] && !!errors?.[name];
|
||||||
|
const errorMessage = isError ? errors?.[name] as string ?? "" : "" ;
|
||||||
return (
|
return (
|
||||||
<div className='LaTeXInput'>
|
<div className='LaTeXInput'>
|
||||||
<label htmlFor={name} className="text">
|
<label htmlFor={name} className="text">
|
||||||
{t(label || name)}
|
<div>{t(label || name)}</div> <div className='error_message'>{t(errorMessage)}</div>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className='LaTeXInputArea'>
|
<div className='LaTeXInputArea'>
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
margin-bottom: 7px !important;
|
margin-bottom: 7px !important;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 19px;
|
font-size: 19px;
|
||||||
|
|
||||||
> span {
|
> span {
|
||||||
color: transparent;
|
color: transparent;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,7 @@ const AddPage: React.FC = () => {
|
||||||
<div onClick={handleCancel}>{t("practical.back")}</div>
|
<div onClick={handleCancel}>{t("practical.back")}</div>
|
||||||
<div
|
<div
|
||||||
className="relative"
|
className="relative"
|
||||||
onClick={()=>{ Loading ? ()=>{} : handleValidateSingleQuestion(values,isValid,handleSubmit) }}
|
onClick={()=>{ handleSubmit() }}
|
||||||
>
|
>
|
||||||
{t("practical.add")}
|
{t("practical.add")}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import SelectTag from "../../../../Components/CustomFields/SelectTag";
|
||||||
import useKeyCombination from "../../../../Hooks/useKeyCombination";
|
import useKeyCombination from "../../../../Hooks/useKeyCombination";
|
||||||
import { CombinationKeyEnum } from "../../../../enums/CombinationKeyEnum";
|
import { CombinationKeyEnum } from "../../../../enums/CombinationKeyEnum";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import LaTeXInput from "../../../../Components/LatextInput/LaTeXInput";
|
|
||||||
import LaTeXInputMemo from "../../../../Components/LatextInput/LaTeXInputMemo";
|
import LaTeXInputMemo from "../../../../Components/LatextInput/LaTeXInputMemo";
|
||||||
import ImageBoxFieldMemo from "../../../../Components/CustomFields/ImageBoxField/ImageBoxFieldMemo";
|
import ImageBoxFieldMemo from "../../../../Components/CustomFields/ImageBoxField/ImageBoxFieldMemo";
|
||||||
|
|
||||||
|
|
@ -48,6 +47,8 @@ const Form = () => {
|
||||||
}
|
}
|
||||||
}, [Success]);
|
}, [Success]);
|
||||||
|
|
||||||
|
console.log(formik.errors);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row className="w-100 exercise_form_container">
|
<Row className="w-100 exercise_form_container">
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,15 @@ export const getValidationSchema = () => {
|
||||||
// validate input
|
// validate input
|
||||||
return Yup.object().shape({
|
return Yup.object().shape({
|
||||||
content_image: Yup.string().nullable(),
|
content_image: Yup.string().nullable(),
|
||||||
content: Yup.string().nullable(),
|
content: Yup.string().test(
|
||||||
|
"content",
|
||||||
|
"validation.one_of_image_and_content_should_be_enter_in_question",
|
||||||
|
(value: any,options:any) => {
|
||||||
|
const {content,content_image} = options?.parent
|
||||||
|
const haveImageOrContent = !(content) && !(content_image)
|
||||||
|
return !haveImageOrContent ;
|
||||||
|
},
|
||||||
|
),
|
||||||
answers: Yup.array().of(
|
answers: Yup.array().of(
|
||||||
Yup.object().shape({
|
Yup.object().shape({
|
||||||
content: Yup.string().nullable(),
|
content: Yup.string().nullable(),
|
||||||
|
|
|
||||||
|
|
@ -360,3 +360,17 @@
|
||||||
@include Scrollbar();
|
@include Scrollbar();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.LaTeXInput{
|
||||||
|
.text{
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
.error_message{
|
||||||
|
color: red;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user