【发布时间】:2020-01-05 14:32:21
【问题描述】:
我想将复选框输入设置为检查特定输入是否填充了值,但可以选择将复选框更改为再次取消选中。
业务需求要求如果用户填写了所需的输入,则应将此复选框设置为自动选中,但如果需要,可以将其设置回未选中状态。(用户体验内容)usecase demo
考虑以下代码:
autoAddFinalEvaluation = () => {
const {channelValue, evaluationValue, txtValue} = this.state;
if(channelValue !== null && evaluationValue !== null && txtValue !== '') {
this.setState({
checked: true
})
}
}
我像这样动态更新状态
autoAddFinalEvaluation = () => {
const {channelValue, evaluationValue, txtValue} = this.state;
if(channelValue !== null && evaluationValue !== null && txtValue !== '') {
this.setState({
checked: !this.state.checked
})
}
}
现在我可以正常设置复选框,但仍然无法按预期工作,在填充第三个输入(文本区域)时,复选框从 true 切换为 false,反之亦然。
【问题讨论】:
-
你能说得更具体一点吗?考虑添加更多代码或更好地解释您的需求。
-
请修改格式
-
@Hurobaki 现在可以了吗?
-
@Abd-AllahEid 有没有办法向我提供你的 React 代码?所以我可以自己测试一下
-
@Hurobaki 感谢您的时间和精力,它现在可以按照以下建议的答案工作
标签: javascript reactjs forms validation user-experience