CheckboxForm.tsx 977 Bytes
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import React, { useState } from "react";
2
3
4
5
import { CheckboxType } from "../types";

type Props = {
  element: CheckboxType;
Jiwon Yoon's avatar
Jiwon Yoon committed
6
  handleQuestion: (id: string) => void;
7
8
};

Jiwon Yoon's avatar
Jiwon Yoon committed
9
10
11
12
13
14
15
16
17
18
export const CheckboxForm = ({ element, handleQuestion }: Props) => {
  const [choices, setChoices] = useState([...element.content.choices]);

  function handleContent(event: React.ChangeEvent<HTMLInputElement>) {
    const { id, value } = event.target;
    choices[+id].text = value;
    element.content.choices = choices;
    handleQuestion(element._id);
    console.log(choices);
  }
19
20

  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
21
22
23
24
25
26
27
28
29
30
31
32
33
    <div id="content" className="flex mt-4">
      {choices.map((choice: any, index: number) => (
        <div>
          <input type="checkbox" disabled></input>
          <input
            id={`${index}`}
            type="text"
            className="mx-2 border-b-2"
            placeholder={choice.text}
            onChange={handleContent}
          ></input>
        </div>
      ))}
34
35
36
    </div>
  );
};