使用material-ui为redux-form设置initialValues将不起作用

时间:2017-06-26 07:37:46

标签: redux material-ui redux-form immutable.js

我想利用我的redux表单来更新一个对象,所以想设置initialValues,我强烈怀疑我做错了什么,但无法弄清楚出了什么问题。

我在github中关注了这个问题并将初始值作为道具传递 https://github.com/erikras/redux-form/issues/916#issuecomment-217437026

            <NoteLayout
            initialValues={values()}
            doc={this.props.Note}
            projects={this.props.ProjectSelector}
            onSubmit={this.props.handleSubmit.bind(this)}/>

我的笔记布局就是这个

class NoteLayout extends React.Component { 
  render() {
  const {handleSubmit, pristine, reset, submitting} = this.props;
return (
  <div>
      <form onSubmit={handleSubmit}>

          <FormSection name="base">
              <BaseBar projects={this.props.projects}/>
          </FormSection>
          <div>
              <Field
                  name="subject"
                  component={renderTextField}
                  label="subject"
              />
          </div>
          <div>
              <Field
                  name="description"
                  fullWidth={true}
                  component={renderTextField}
                  label="description"
              />
          </div>
          <div>
              <RaisedButton
                  style={style}
                  fullWidth={false}
                  primary={true}
                  type="submit"
                  disabled={pristine || submitting}>
                  Submit
              </RaisedButton>
              <RaisedButton
                  style={style}
                  fullWidth={false}
                  secondary={false}
                  type="button"
                  disabled={pristine || submitting}
                  onClick={reset}>
                  Clear Values
              </RaisedButton>
          </div>
      </form>
  </div>
);


}
}

NoteLayout.propTypes = {

};

export default reduxForm({
    form: 'NoteLayout',
    validate
})(NoteLayout);

Props and form

1 个答案:

答案 0 :(得分:0)

redux-form / immutable是答案,我可能看起来不正确,不可变的关键字帮助了我。

https://github.com/erikras/redux-form/issues/1744#issuecomment-252269843