Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getFieldDecorator rules for password reset?

Tags:

reactjs

antd

I'm trying to do a "field 2 does not match field 1" thing here (i.e. "passwords do not match).

There isn't much documentation on the available rules for the antd forms. They point at this project here.

Below is my current form:

const ResetPasswordForm = Form.create()(React.createClass({
  getInitialState () {
    return {
      loading: false
    };
  },
  handleSubmit(e) {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (err) {
        failure();
      }
      if (!err) {
        let newPassword = values.newPassword;
        let repeatNewPassword = values.repeatNewPassword;
        handleResetPassword(newPassword, repeatNewPassword, this.props.token);
      }
    });

  },
  render() {
    const { getFieldDecorator } = this.props.form;

    const newPasswordRules = [
      { required: true, message: 'Please input a new password!' }
    ];

    const repeatNewPassword = [
      { required: true, message: 'Please repeat the new password!' }
    ];

    return (
      <Form onSubmit={this.handleSubmit} className="login-form">
        <FormItem>
          {getFieldDecorator('newPassword', { rules: newPasswordRules })(
            <Input addonBefore={<Icon type="lock" />} type="password" placeholder="New password" />
          )}
        </FormItem>
        <FormItem>
          {getFieldDecorator('repeatNewPassword', { rules: repeatNewPassword })(
            <Input addonBefore={<Icon type="lock" />} type="password" placeholder="Repeat new password" />
          )}
        </FormItem>
        <FormItem>
          <Button loading={this.state.loading} type="primary" htmlType="submit" className={css(styles.loginButton)}>
            Reset Password
          </Button>
        </FormItem>
      </Form>
    );
  }
}));

If anyone can point me in the right direction for creating a rule that checks that the first field value matches the second, that'd be awesome!

like image 224
arcom Avatar asked Jan 06 '17 15:01

arcom


People also ask

How do I reset my password in react native?

Log in to your App dashboard, go to Settings->Verification Emails and change your password reset email subject or message.

How do you use the getFieldDecorator in ANTD?

Just use Form. Item directly: // antd v3 const Demo = ({ form: { getFieldDecorator } }) => ( <Form> <Form. Item> {getFieldDecorator('username', { rules: [{ required: true }], })(<Input />)} </Form.

How do you reset a particular field in ANTD?

resetFields() does is set all field values back to their initialValues . What you want, then, is to reset only the title field to its initial value.


1 Answers

You can find it in this register form demo: https://ant.design/components/form/#components-form-demo-register

like image 114
afc163 Avatar answered Sep 29 '22 09:09

afc163