0

我尝试使用admin-on-rest实现一个用于创建新用户的页面。我想添加两个字段,PasswordRepeat Password能指导我吗?我<TextInput source="password" type="password" validate={ required }/>用于Password字段,但是呢Repeat Password

我们如何验证Repeat Password

我不知道我们如何创建这个页面。

4

1 回答 1

0

通过这个问题回答验证 redux 形式的确认密码是有效的。

我的例子:

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>
);

于 2020-01-17T03:50:14.640 回答