以redux格式在文本字段中设置初始值

时间:2017-03-26 11:32:34

标签: javascript reactjs default-value redux-form

我想创建一个输入文本字段,如上图所示,并且我使用redux格式。我输入字段组件的代码如下:

<input
      {...props.input}
      type={props.type}
      className="form-control input-box__input"
      placeholder={props.placeholder}
      value={props.value}
    />

enter image description here

在Field标签中,我的代码是:

                <Field
                  id="currentPassword"
                  name="currentPassword"
                  component={inputField}
                  type="text"
                  disabled
                  value={userSettings.map(i => i.currentPassword)}
                />

同样在我的容器中我使用这样的initialValues:

initialValues: fromJS({
      currentPassword: ownProps.currentPassword,

但它似乎不起作用。你知道为什么吗?

1 个答案:

答案 0 :(得分:0)

你应该使用initialValues,例如:

const Wrapper = (props) => {
 class Login extends Component {
   ...
 }
 const LoginForm = reduxForm({
  form: 'LoginForm',
  initialValues: {
    currentPassword: "initial currentPassword",
  },
 })(Login);
 return <LoginForm {...props} />;
}

<LoginForm
 initialValues={initialValues}
/>

http://redux-form.com/6.0.0-alpha.4/examples/initializeFromState/

相关问题