|
|
@ -78,94 +78,92 @@ class BasicDemo extends React.Component { |
|
|
|
|
|
|
|
render() { |
|
|
|
const { getFieldProps, getFieldError, isFieldValidating } = this.props.form; |
|
|
|
|
|
|
|
const nameProps = getFieldProps('name', { |
|
|
|
rules: [ |
|
|
|
{ required: true, min: 5, message: '用户名至少为 5 个字符' }, |
|
|
|
{ validator: this.userExists }, |
|
|
|
], |
|
|
|
}); |
|
|
|
const emailProps = getFieldProps('email', { |
|
|
|
validate: [{ |
|
|
|
rules: [ |
|
|
|
{ required: true }, |
|
|
|
], |
|
|
|
trigger: 'onBlur', |
|
|
|
}, { |
|
|
|
rules: [ |
|
|
|
{ type: 'email', message: '请输入正确的邮箱地址' }, |
|
|
|
], |
|
|
|
trigger: ['onBlur', 'onChange'], |
|
|
|
}] |
|
|
|
}); |
|
|
|
const passwdProps = getFieldProps('passwd', { |
|
|
|
rules: [ |
|
|
|
{ required: true, whitespace: true, message: '请填写密码' }, |
|
|
|
{ validator: this.checkPass.bind(this) }, |
|
|
|
], |
|
|
|
}); |
|
|
|
const rePasswdProps = getFieldProps('rePasswd', { |
|
|
|
rules: [{ |
|
|
|
required: true, |
|
|
|
whitespace: true, |
|
|
|
message: '请再次输入密码', |
|
|
|
}, { |
|
|
|
validator: this.checkPass2.bind(this), |
|
|
|
}], |
|
|
|
}); |
|
|
|
const textareaProps = getFieldProps('textarea', { |
|
|
|
rules: [ |
|
|
|
{ required: true, message: '真的不打算写点什么吗?' }, |
|
|
|
], |
|
|
|
}); |
|
|
|
const formItemLayout = { |
|
|
|
labelCol: { span: 7 }, |
|
|
|
wrapperCol: { span: 12 }, |
|
|
|
}; |
|
|
|
return ( |
|
|
|
<Form horizontal form={this.props.form}> |
|
|
|
<FormItem |
|
|
|
{...formItemLayout} |
|
|
|
label="用户名:" |
|
|
|
labelCol={{ span: 7 }} |
|
|
|
wrapperCol={{ span: 12 }} |
|
|
|
hasFeedback |
|
|
|
help={isFieldValidating('name') ? '校验中...' : (getFieldError('name') || []).join(', ')}> |
|
|
|
<Input placeholder="实时校验,输入 JasonWood 看看" |
|
|
|
{...getFieldProps('name', { |
|
|
|
rules: [ |
|
|
|
{ required: true, min: 5, message: '用户名至少为 5 个字符' }, |
|
|
|
{ validator: this.userExists }, |
|
|
|
], |
|
|
|
})} /> |
|
|
|
<Input {...nameProps} placeholder="实时校验,输入 JasonWood 看看" /> |
|
|
|
</FormItem> |
|
|
|
|
|
|
|
<FormItem |
|
|
|
{...formItemLayout} |
|
|
|
label="邮箱:" |
|
|
|
labelCol={{ span: 7 }} |
|
|
|
wrapperCol={{ span: 12 }} |
|
|
|
hasFeedback> |
|
|
|
<Input type="email" placeholder="onBlur 与 onChange 相结合" |
|
|
|
{...getFieldProps('email', { |
|
|
|
validate: [{ |
|
|
|
rules: [ |
|
|
|
{ required: true }, |
|
|
|
], |
|
|
|
trigger: 'onBlur', |
|
|
|
}, { |
|
|
|
rules: [ |
|
|
|
{ type: 'email', message: '请输入正确的邮箱地址' }, |
|
|
|
], |
|
|
|
trigger: ['onBlur', 'onChange'], |
|
|
|
}] |
|
|
|
})} /> |
|
|
|
<Input {...emailProps} type="email" placeholder="onBlur 与 onChange 相结合" /> |
|
|
|
</FormItem> |
|
|
|
|
|
|
|
<FormItem |
|
|
|
{...formItemLayout} |
|
|
|
label="密码:" |
|
|
|
labelCol={{ span: 7 }} |
|
|
|
wrapperCol={{ span: 12 }} |
|
|
|
hasFeedback> |
|
|
|
<Input type="password" autoComplete="off" |
|
|
|
{...getFieldProps('passwd', { |
|
|
|
rules: [ |
|
|
|
{ required: true, whitespace: true, message: '请填写密码' }, |
|
|
|
{ validator: this.checkPass.bind(this) }, |
|
|
|
], |
|
|
|
})} |
|
|
|
<Input {...passwdProps} type="password" autoComplete="off" |
|
|
|
onContextMenu={noop} onPaste={noop} onCopy={noop} onCut={noop} /> |
|
|
|
</FormItem> |
|
|
|
|
|
|
|
<FormItem |
|
|
|
{...formItemLayout} |
|
|
|
label="确认密码:" |
|
|
|
labelCol={{ span: 7 }} |
|
|
|
wrapperCol={{ span: 12 }} |
|
|
|
hasFeedback> |
|
|
|
<Input type="password" autoComplete="off" placeholder="两次输入密码保持一致" |
|
|
|
onContextMenu={noop} onPaste={noop} onCopy={noop} onCut={noop} |
|
|
|
{...getFieldProps('rePasswd', { |
|
|
|
rules: [{ |
|
|
|
required: true, |
|
|
|
whitespace: true, |
|
|
|
message: '请再次输入密码', |
|
|
|
}, { |
|
|
|
validator: this.checkPass2.bind(this), |
|
|
|
}], |
|
|
|
})} /> |
|
|
|
<Input {...rePasswdProps} type="password" autoComplete="off" placeholder="两次输入密码保持一致" |
|
|
|
onContextMenu={noop} onPaste={noop} onCopy={noop} onCut={noop} /> |
|
|
|
</FormItem> |
|
|
|
|
|
|
|
<FormItem |
|
|
|
label="备注:" |
|
|
|
labelCol={{ span: 7 }} |
|
|
|
wrapperCol={{ span: 12 }}> |
|
|
|
<Input type="textarea" placeholder="随便写" id="textarea" name="textarea" |
|
|
|
{...getFieldProps('textarea', { |
|
|
|
rules: [ |
|
|
|
{ required: true, message: '真的不打算写点什么吗?' }, |
|
|
|
], |
|
|
|
})} /> |
|
|
|
{...formItemLayout} |
|
|
|
label="备注:"> |
|
|
|
<Input {...textareaProps} type="textarea" placeholder="随便写" id="textarea" name="textarea" /> |
|
|
|
</FormItem> |
|
|
|
|
|
|
|
<FormItem wrapperCol={{ span: 12, offset: 7 }} > |
|
|
|
<Button type="primary" onClick={this.handleSubmit.bind(this)}>确定</Button> |
|
|
|
<FormItem wrapperCol={{ span: 12, offset: 7 }}> |
|
|
|
<Button type="primary" onClick={this.handleSubmit.bind(this)}>确定</Button> |
|
|
|
|
|
|
|
<Button type="ghost" onClick={this.handleReset.bind(this)}>重置</Button> |
|
|
|
<Button type="ghost" onClick={this.handleReset.bind(this)}>重置</Button> |
|
|
|
</FormItem> |
|
|
|
</Form> |
|
|
|
); |
|
|
|