import React from 'react'; import classnames from 'classnames'; import { Form, Input, Row, Col } from 'antd'; import { FormItemProps } from 'antd/lib/form'; import { WrappedFormUtils } from 'antd/lib/form/Form'; export interface Props { form: WrappedFormUtils; className?: string; formItemProps?: FormItemProps; } const STATE = { passwordConfirmDirty: true, }; type State = typeof STATE; export default class AddressInput extends React.Component { state: State = { ...STATE }; render() { const { passwordConfirmDirty } = this.state; const { className } = this.props; const { getFieldDecorator, validateFields, getFieldValue } = this.props.form; const passedFormItemProps = this.props.formItemProps || {}; const formItemProps = { className: classnames(className, passedFormItemProps.className), }; return ( {getFieldDecorator('password', { rules: [ { required: true, message: 'Please enter a password' }, { min: 8, message: 'Please use at least 8 characters' }, { validator: (_, val, cb) => { if (val && passwordConfirmDirty) { validateFields(['passwordConfirm'], { force: true }); } cb(); }, }, ], })( , )} {getFieldDecorator('passwordConfirm', { rules: [ { required: true, message: 'Please confirm password' }, { validator: (_, val, cb) => { if (val && val !== getFieldValue('password')) { cb('Passwords do not match'); } else { cb(); } }, }, ], })( this.setState({ passwordConfirmDirty: passwordConfirmDirty || !!e.target.value, }) } placeholder="" autoComplete="off" />, )} ); } }