文档地址
import React, { useState, useEffect } from "react";
import { Form, Input, Button } from "antd";
import { UserOutlined, LockOutlined } from "@ant-design/icons";
export default function App(props) {
const [form] = Form.useForm();
return (
<Form
form={form}
name="horizontal_login"
layout="inline"
onFinish={(values) => {
console.log(values);
}}
>
<Form.Item
name="username"
rules={[
{
required: true,
message: "Please input your username!",
},
]}
>
<Input
prefix={<UserOutlined className="site-form-item-icon" />}
placeholder="Username"
/>
</Form.Item>
<Form.Item
name="password"
rules={[
{
required: true,
message: "Please input your password!",
},
]}
>
<Input
prefix={<LockOutlined className="site-form-item-icon" />}
type="password"
placeholder="Password"
/>
</Form.Item>
<Form.Item shouldUpdate>
{() => {
console.log(form.isFieldsTouched(true));
console.log(form.getFieldsError());
return (
<Button type="primary" htmlType="submit" disabled={
!form.isFieldsTouched(true)||!!form.getFieldsError().filter((item)=>{
return !!item.errors.length
}).length
}>
登录
</Button>
);
}}
</Form.Item>
</Form>
);
}
|