diff --git a/src/components/typeAnswer/DropDownList.jsx b/src/components/typeAnswer/DropDownList.jsx index 87a6e26..8b3c99c 100644 --- a/src/components/typeAnswer/DropDownList.jsx +++ b/src/components/typeAnswer/DropDownList.jsx @@ -9,7 +9,9 @@ const DropDownList = (props) => { {item.text} )} */} - + props.updateAnswersForm(Number(e.target.value), props.id) : () => {}}> {props.optionAnswer.map((item, i) => {item.text} )} diff --git a/src/components/typeAnswer/InputMultipleRadio.jsx b/src/components/typeAnswer/InputMultipleRadio.jsx index 309a151..281f880 100644 --- a/src/components/typeAnswer/InputMultipleRadio.jsx +++ b/src/components/typeAnswer/InputMultipleRadio.jsx @@ -2,11 +2,38 @@ import React from "react"; import classes from "../../assets/styles/components/typeAnswer/inputMultiple.module.scss" const InputMultipleRadio = (props) => { + function checkRadio(i) { + if (props.answers[props.id].answer) { + return props.answers[props.id].answer.some(item => item === Number(i)) + } + return false + } + + function updateStateCheckbox(i) { + if (props.updateAnswersForm) { + if (props.answers[props.id].answer.some((item) => item === Number(i))) { + props.answers[props.id].answer.splice(props.answers[props.id].answer.indexOf(i), 1) + } + else { + props.answers[props.id].answer.push(i) + } + props.updateAnswersForm(props.answers[props.id].answer, props.id) + } + } + return ( {props.optionAnswer.map((item, i) => - + updateStateCheckbox(i)} + /> {item.text} )} diff --git a/src/components/typeAnswer/InputRadio.jsx b/src/components/typeAnswer/InputRadio.jsx index 6cfff78..c9e27a6 100644 --- a/src/components/typeAnswer/InputRadio.jsx +++ b/src/components/typeAnswer/InputRadio.jsx @@ -13,7 +13,8 @@ const InputRadio = (props) => { id={`choice_${item.id}`} value={i} checked={props.answers ? props.answers[props.id].answer === i : false} - onChange={props.updateAnswersForm ? (e) => props.updateAnswersForm(Number(e.target.value), props.id) : () => {}}/> + onChange={props.updateAnswersForm ? (e) => props.updateAnswersForm(Number(e.target.value), props.id) : () => {}} + /> {item.text} )} diff --git a/src/pages/Forms.jsx b/src/pages/Forms.jsx index a8a61bf..135f182 100644 --- a/src/pages/Forms.jsx +++ b/src/pages/Forms.jsx @@ -56,7 +56,7 @@ const Forms = () => { {forms.map((item, i) => editForm(item)}>{item.title} - {item.answers} + {item.datetime} {item.update} diff --git a/src/pages/ViewForm.jsx b/src/pages/ViewForm.jsx index b42160b..9fb2910 100644 --- a/src/pages/ViewForm.jsx +++ b/src/pages/ViewForm.jsx @@ -17,12 +17,11 @@ const ViewForm = () => { const [answers, setAnswers] = useState( newForm() ? newForm().listAnswer.map(item => ( - {id: item.id, answer: ""} + {id: item.id, answer: []} )) : "" ); function updateAnswersForm(value, id) { - console.log(value, id) setAnswers( answers.map((item, i) => { if (id === i) {