首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将Antd输入和Form.Item包装在另一个组件中,不触发验证

将Antd输入和Form.Item包装在另一个组件中,不触发验证
EN

Stack Overflow用户
提问于 2022-08-29 21:19:37
回答 1查看 34关注 0票数 -1

我试图将Antd &输入封装在单独的TextBox组件中,这样我就可以添加对自定义本地化的支持,但是如果我在Antd表单中添加自定义组件,验证就无法工作。例如,我想创建一个TextBox组件,它呈现

代码语言:javascript
运行
复制
<Form
  name="basic"
  labelCol={{ span: 8 }}
  wrapperCol={{ span: 16 }}
  initialValues={{ remember: true }}
  onFinish={onFinish}
  onFinishFailed={onFinishFailed}
  autoComplete="off"
>
  <TextBox
    label="Username"
    name="username"
    rules={[{ required: true, message: 'Please input your username!' }]}
  >
  </TextBox>

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

  <TextBox name="remember" valuePropName="checked" wrapperCol={{ offset: 8, span: 16 }}>
    <Checkbox>Remember me</Checkbox>
  </TextBox>

  <TextBox wrapperCol={{ offset: 8, span: 16 }}>
    <Button type="primary" htmlType="submit">
      Submit
    </Button>
  </TextBox>
</Form>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-03 20:46:19

这是一个非常愚蠢的问题,因为我忘记在输入字段上指定名称,这样就没有验证。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73534781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档