Editable combo box in Redux-Form

若如初见. 提交于 2020-01-17 05:06:26

问题


Something to similar with this thread: How can I create an editable combo box in HTML/Javascript?

Is it possible to have a combo-box form in Redux-Form?


回答1:


This works for me:

<Field
    options={[
      {value: 1, text: 'Option1'},
      {value: 2, text: 'Option2'}
    ]}
    component={Select}
    label="My select question"
    className="col-md-6"
  />

const Select = ({input, options, label, error}) => {
  if (error && error.length > 0) {
    className += " " + 'has-error'
  }
  return (
    <div className={className}>
      {label && <label htmlFor={input.name}>{label}</label>}
        <select {...input} >
          {options.map(function (option, i) {
            return (
              <option
                value={option.value}
                key={i}
              >
                {option.text}
              </option>)
          })}
        </select>
        {error && <div className="alert alert-danger">{error}</div>}
    </div>
  )
}


来源:https://stackoverflow.com/questions/41173975/editable-combo-box-in-redux-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!