【问题标题】:Selecting form values in redux-from在 redux-from 中选择表单值
【发布时间】:2019-03-18 09:21:55
【问题描述】:

我想在使用 redux-from 单击单选按钮时显示表单,这是我关注的教程链接,(使用复选框实现) selectingformvalues 但我无法在单选按钮上实现它,

我有 2 个单选按钮

单选按钮x点击,显示a表单

单选按钮y点击,显示b表格并隐藏a表格

    <label htmlFor="hasEmail">percentage</label>
    <div>
      <Field
        name="taxtype"
        component="input"
        type="radio"
        value="percentage"
      />
    </div>
  </div>
  <div>
    <label htmlFor="hasEmail">usd</label>
    <div>
      <Field
        name="taxtype"
        component="input"
        type="radio"
        value="usd"
      />
    </div>
  </div>
  {usd && (
    <div>
      <label>Email</label>
      <div>
        <Field
          name="email"
          component="input"
          type="email"
          placeholder="Email"

        />
      </div>
    </div>
  )}

  {percentage && (
    <div>
      <label>Email 2</label>
      <div>
        <Field
          name="email"
          component="input"
          type="email"
          placeholder="Email"

        />
      </div>
    </div>
  )}



 const percentage = selector(state, 'percentage')
  const usd = selector(state, 'usd')

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 点击单选按钮时打开不同的表单,表单取决于单选按钮的值
  • 您必须向我们提供您的一些无效代码。

标签: javascript reactjs redux redux-form


【解决方案1】:

这是您提到的示例,您重写为包括两个收音机

https://codesandbox.io/s/koz449qo6o

【讨论】:

  • 感谢您的回答,但我需要它在单选按钮中,因为在复选框中我们可以同时选择这就是问题所在
  • 你试过把type="checkbox"改成type="radio"吗?
  • 是的,它的;不起作用,因为单选按钮的工作方式与复选框不同
  • 我更新了代码,你可以在这里找到一个工作版本:codesandbox.io/s/koz449qo6o
猜你喜欢
  • 2021-08-19
  • 1970-01-01
  • 1970-01-01
  • 2010-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多