37 lines
1015 B
TypeScript
37 lines
1015 B
TypeScript
import React from "react";
|
|
import useFormField from "../../../../Hooks/useFormField";
|
|
import { Checkbox, Form } from "antd";
|
|
import { useFormik, useFormikContext } from "formik";
|
|
import { useTranslation } from "react-i18next";
|
|
const CheckboxField = ({
|
|
name,
|
|
label,
|
|
isDisabled,
|
|
onChange,
|
|
Group,
|
|
className,
|
|
props,
|
|
}: any) => {
|
|
const formik = useFormikContext<any>()
|
|
const [t] = useTranslation()
|
|
const CheckboxhandleChange = (value: any) => {
|
|
console.log(value?.target?.checked);
|
|
|
|
formik.setFieldValue(`QuestionOptions[${name}].isCorrect`, value?.target?.checked ? 1 : 0);
|
|
};
|
|
return (
|
|
<div className={Group ? "d-inline mt-5 Checkbox" : ``}>
|
|
<Checkbox
|
|
onChange={onChange || CheckboxhandleChange}
|
|
disabled={isDisabled}
|
|
checked={formik.values?.QuestionOptions?.[name]?.isCorrect === 1}
|
|
className={className}
|
|
>
|
|
{t(`input.${label ? label : name}`)}
|
|
</Checkbox>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default CheckboxField;
|