繁体   English   中英

在redux形式的文本字段中设置初始值

[英]Setting an initial value in an text field in redux form

我想创建一个输入文本字段,如上图,我正在使用redux表单。 我的输入字段组件代码如下:

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

在此处输入图片说明

在字段标签中,我的代码是:

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

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

initialValues: fromJS({
      currentPassword: ownProps.currentPassword,

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

您应该使用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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM