Ant Design:验证表单字段 w/custom 个验证器
Ant Design: Validating form fields w/custom validators
我想使用 notifications 来推送表单反馈,而不是内联消息。例如
<Form.Item label="Name">
{getFieldDecorator("name", {
rules: [
{
validator(rule, value, callback) {
if (!value) {
callback("Enter Your Name");
// I'd like to use this instead:
// notification.open({
// message: "Enter Your Name",
// description:
// 'This is the content of the notification.',
// })
}
callback();
}
}
]
})(<Name />)}
</Form.Item>;
是否可以在没有内联消息的情况下验证表单字段并维护视觉反馈(即类似 border-color
更改的内容)?
您可以使用 this.props.form.setFields
抛出自定义错误消息
this.props.form.setFields({
user: {
value: values.user,
errors: [new Error('forbid ha')],
},
});
您可以按照代码中的说明进行操作,并使用 css 隐藏错误消息。
display: none
我想使用 notifications 来推送表单反馈,而不是内联消息。例如
<Form.Item label="Name">
{getFieldDecorator("name", {
rules: [
{
validator(rule, value, callback) {
if (!value) {
callback("Enter Your Name");
// I'd like to use this instead:
// notification.open({
// message: "Enter Your Name",
// description:
// 'This is the content of the notification.',
// })
}
callback();
}
}
]
})(<Name />)}
</Form.Item>;
是否可以在没有内联消息的情况下验证表单字段并维护视觉反馈(即类似 border-color
更改的内容)?
您可以使用 this.props.form.setFields
抛出自定义错误消息this.props.form.setFields({
user: {
value: values.user,
errors: [new Error('forbid ha')],
},
});
您可以按照代码中的说明进行操作,并使用 css 隐藏错误消息。
display: none