redux-form renderField类型radio未定义的值

时间:2017-01-25 16:35:01

标签: reactjs radio redux-form

我尝试为单选按钮实现renderField,我可以显示它但是当我点击无线电字段时没有填充。 当我检查控制台时,输入值等于undefined,总是!

这是我的代码:

render(){
    const {input, array, meta, label} = this.props;
    return(
      <div className="input-row">
        <div className="radio-box">
          {array.map((option,i) =>
            <div className="radio-field" key={i}>
              <input type='radio' name={option.name} onChange={() => {input.onChange('oui')}} value={option.value} checked={input.value === option.value} />
              {/* Try this before <input type='radio' {...input} name={option.name} value={option.value} checked={input.value == option.value}/> */}
              <label>{option.name}</label>
            </div>
          )}
        </div>
      </div>
    )
  }

我称之为:

<Field name="courtage" type="radio" label="Courtage ?" component={renderRadioField} array={selectOptions.courtage} {...courtage} />

SelectOptions.courtage是一个对象数组。

1 个答案:

答案 0 :(得分:0)

几个小时后,我找到了一个解决方案,我和州一起玩:

  setRadioState(a) {
    const obj = {};
    obj[a.target.name] = a.target.value;
    this.setState(obj);
  }

  render(){
    const {input, array, meta, label, name} = this.props;
    return(
      <div className="input-row">
        <div className="label-box">
          <label>{label}</label>
        </div>
        <div className="radio-box">
          {array.map((option,i) =>
            <div className="radio-field" key={i}>
              <input type='radio' name={name} {...input} onChange={this.setRadioState.bind(this)} value={option.value} checked={this.state.name} />
              <label>{option.name}</label>
            </div>
          )}
          {/* <div className="errors">{meta.touched && ((error && <span>{error}</span>))}</div> */}
        </div>
      </div>
    )