输入初始值时输入已变为只读

时间:2019-05-04 10:39:31

标签: reactjs input reactstrap

当我将 restraps input字段的值设置为某个值时,它将变为readonly

    <Col md="6">
      <FormGroup>
        <Label htmlFor="department">Department</Label>
        <Field
          id="department"
          name="department"
          type="text"
          component={InputAdapter}
          initvalue={type?kpi.department:''}
        />
        <FormFeedbackAdapter name="department" />
      </FormGroup>
    </Col>

我正在使用 react-final-form 中的字段,如上面的代码n所示。然后

    const InputAdapter = (
  {
    input,
    meta,
    initvalue,
    invalid = meta => meta.touched && meta.invalid,
    valid = () => false,
    ...rest
  }
) => <Input { ...input } { ...rest } invalid={ invalid(meta) } valid={ valid(meta) } value={initvalue}/>

InputAdapter.propTypes = {
  invalid: PropTypes.func,
  valid:   PropTypes.func,
}

这是InputAdapter组件。在这里,我将值设置为初始值。但是此后该字段将变为只读。选择类型输入也存在同样的问题。

1 个答案:

答案 0 :(得分:2)

您要设置defaultValue=而不是value=。设置了值的输入将变为controlled components,即您正在观察的行为。