Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React-ant设计表单验证不起作用(提交时)_Javascript_Css_Reactjs_Antd - Fatal编程技术网

Javascript React-ant设计表单验证不起作用(提交时)

Javascript React-ant设计表单验证不起作用(提交时),javascript,css,reactjs,antd,Javascript,Css,Reactjs,Antd,当我按submit时,如果电子邮件/密码中没有填写任何内容,则会在其下方显示一条消息,说明需要电子邮件/密码,但这不会发生 代码沙盒链接: import'/App.css'; 从“antd”导入{按钮、表单、输入、复选框} 导入“antd/dist/antd.css”; 函数App(){ 返回( 注册 输入电子邮件: 输入密码: 记得我吗 提交 ); } 导出默认应用程序``` 您需要为表单.Item组件指定名称属性。antd表单实用程序与name一起工作。所以,因为您尚未为文本输入字段定义名称

当我按submit时,如果电子邮件/密码中没有填写任何内容,则会在其下方显示一条消息,说明需要电子邮件/密码,但这不会发生

代码沙盒链接:

import'/App.css';
从“antd”导入{按钮、表单、输入、复选框}
导入“antd/dist/antd.css”;
函数App(){
返回(
注册
输入电子邮件:
输入密码:
记得我吗
提交
);
}
导出默认应用程序```

您需要为
表单.Item
组件指定
名称
属性。
antd
表单实用程序与
name
一起工作。所以,因为您尚未为文本输入字段定义名称,所以它无法验证或读取其值。 您应该更改
表单。项目
如下:

      <Form.Item
        name="email"
        rules={[
          {
            required: true,
            message: 'Please input your email!',
          },
        ]}
      >
        <Input placeholder="Enter Email" />
      </Form.Item>

      <Form.Item
        name="password"
        rules={[
          {
            required: true,
            message: 'Please input your password!',
          },
        ]}
      >
        <Input.Password placeholder="Enter Password" />
      </Form.Item>

      <Form.Item
        name="email"
        rules={[
          {
            required: true,
            message: 'Please input your email!',
          },
        ]}
      >
        <Input placeholder="Enter Email" />
      </Form.Item>

      <Form.Item
        name="password"
        rules={[
          {
            required: true,
            message: 'Please input your password!',
          },
        ]}
      >
        <Input.Password placeholder="Enter Password" />
      </Form.Item>