【发布时间】:2021-07-23 00:19:04
【问题描述】:
我有一个模态表,其代码如下所示。
<div>
<Table>
<tbody>
{props.data.map((p) => <>
<tr>
<th> STC </th>
<th> Edit Text</th>
</tr>
<tr index={p}>
<td key={p.stc}><h3>{p.stc}</h3></td>
<td >
<TextField name={p.stc} type="text" value={p.readValue} onChange={handleChange} required={true} size="small" label="Required" variant="outlined" />
</td>
</tr>
</>)}
</tbody>
</Table>
<div >
<Button disabled={inputState.disable} className="buttonStyle" onClick={(e) => submit()}>SUBMIT</Button>
<Button onClick={handleClose}>CANCEL</Button>
</div>
</div>
以及它们对应的函数和声明如下-
const [formInput, setFormInput] = useReducer(
(state, newState) => ({ ...state, ...newState }),
);
const [inputState, setInputState] = useState({disable: true});
const handleOpen = (e) => {
setOpen(true);
};
const handleClose = () => {
window.location.reload(false);
setOpen(false);
};
const [readValue, writeValue] = useState("");
const submit = (e) => {
console.log("Submitted!")
handleClose();
}
const handleChange = (event) => {
const newValue = event.target.value;
writeValue(event.target.value)
setInputState({disable: event.target.value===''})
}
我想要-
- 禁用按钮,直到所有 TextField 都填满为止。
- 在 handleClose() 中,是否有任何替代解决方案可以清除 TextFields 的值而不是 window.reload?
格式看起来像我在下面附上的图片 - enter image description here
【问题讨论】:
-
问题已经回答了。检查下面的链接stackoverflow.com/questions/36813148/…
-
这里还有一个关于如何使用反应状态来完成的要点示例:gist.github.com/ypan887/92d6f1c5028388bd8a6851fdf034968d
-
@Encoder'sYT 这些是表格。我没有表格。我需要表格输入验证
标签: html reactjs html-table react-hooks frontend