0

I try to implement a page for create new users with admin-on-rest. I want to add two fields for Password and Repeat Password Can you guide me. I use <TextInput source="password" type="password" validate={ required }/> for Password field but what about Repeat Password?

How We can validate Repeat Password?

I havent any idea for how we can create this page.

b24
  • 2,425
  • 6
  • 30
  • 51
  • 1
    check out [redux-form validate](http://redux-form.com/6.8.0/docs/api/Field.md/). AOR field's validate is the same as redux-form's and you can access password from `allValues.password`. – wesley6j Jun 19 '17 at 13:46
  • I try that but I have new error now: https://stackoverflow.com/questions/48898743/prevent-field-to-send-in-request – b24 Feb 21 '18 at 05:31

1 Answers1

0

Answer by this question validate confirmation password in redux form is works.

My example:

import React from 'react';
import { SimpleForm, TextInput, Create } from 'react-admin';
import { required, email } from 'react-admin';

const PasswordValidate = values => {
    const errors = {};
    if (!values.username) {
        errors.username = 'Required';
    }
    if (!values.password) {
        errors.password = 'Required';
    }
    if (!values.confirmPassword ) {
        errors.confirmPassword = 'Required' ;
    } else if (values.confirmPassword !== values.password) {
        errors.confirmPassword = 'Password mismatched' ;
    }

    return errors;
};

export const UserCreate = (props) => (
    <Create {...props}>
        <SimpleForm validate={PasswordValidate}>
            <TextInput source="email" type="email" validate={[required(), email()]} />
            <TextInput source="username" />
            <TextInput label="Password" source="password" validate={required()} />
            <TextInput label="Repeat password" source="confirmPassword" type="password" validate={required()} />
        </SimpleForm>
    </Create>
);