我使用的是react-hook-form V7.14.2,并且使用的是Material-UI复选框,用户可以手动检查该复选框,也可以根据某些输入的值自动检查该复选框。这工作正常。
问题是,在提交表单时,如果通过逻辑选中复选框,则根据某些输入的值,发送到后端的值将为 false。如果用户手动选中该复选框,那么它将发送正确的值。-如果选中则为真-。
我在react-hook-form页面中阅读了从V6迁移到V7的文档,因为我之前使用的是V6并且代码在那里工作。 https://react-hook-form.com/migrate-v6-to-v7/
我还阅读了 Stackoverflow 中以前的一些答案,例如:material-ui checkbox with react-hook-form但没有成功。
这是我的代码:
import React, { useContext, useState, useEffect } from "react";
import Checkbox from "@material-ui/core/Checkbox";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCheckCircle } from "@fortawesome/free-solid-svg-icons";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import { Controller, set } from "react-hook-form";
import { makeStyles } from "@material-ui/core/styles";
import { DarkThemeContext } from "../../context/DarkThemeContext";
import { useStylesSelectPropDetails } from "../../styledComponent/SelectPropDetailsStyled";
import { IMAGES_LINK } from "../../api/doFetch";
const useStylesLabel = makeStyles((theme) => …Run Code Online (Sandbox Code Playgroud)