【问题标题】:Is there any way in Redux form to have checkbox with three options, like positive, negative and not selected?Redux 表单中是否有任何方法可以让复选框具有三个选项,例如正面、负面和未选中?
【发布时间】:2019-05-26 01:23:01
【问题描述】:

我正在处理一个带有三向复选框的表单 - 正面、负面或未选中。

我想知道是否有任何使用 redux-form 字段的好例子。

任何帮助将不胜感激,谢谢。

【问题讨论】:

  • 这个问题似乎根本不包括解决问题的任何尝试。StackOverflow 希望您try to solve your own problem first,因为您的尝试有助于我们更好地了解您想要什么。请编辑问题以显示您尝试过的内容,并使用Minimal, Complete, and Verifiable 示例显示您遇到的特定障碍。欲了解更多信息,请参阅How to Ask
  • 我很好奇这里的场景是什么?复选框似乎不完全适合这里的工作,因为复选框包含二进制信息,但您需要三进制。
  • 好建议亨利,但是我们有复选框以旧应用程序中提到的方式工作,我们现在正在编写反应。因此,如果可能的话,希望不要改变用户体验。
  • 这是三个选项选择的场景,而不是复选框

标签: reactjs checkbox react-redux redux-form


【解决方案1】:

虽然您正在寻找的 UX 的完美 UI 元素是

https://github.com/jchiam/react-three-state-checkbox

【讨论】:

    【解决方案2】:

    你可以这样实现:

      <Field
        type="checkbox"
        name="absolute"
        value="negative"
        validate={[required]}
        component={checkbox}
        label="negative"
      />
    
     <Field
        type="checkbox"
        name="absolute"
        value="positive"
        validate={[required]}
        component={checkbox}
        label="positive"
      />
    

    Initially it will be not selected any value, when any of the value is selected it will be set as positive/negative.

    希望这会有所帮助。

    【讨论】:

    • 感谢您的回复。我们如何根据它显示右刻度、减刻度或空框?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多