例如,这是我的Form.Item组件,添加规则似乎不起作用。我不希望表单被提交,除非在上传区域上传了一些东西。尝试将验证规则也放入中,但这也不起作用。
<Form.Item
style={{ display: "inline-block", }}
>
<Upload.Dragger
multiple
rules={[
{
required: true,
message: "Please upload",
},
]}
>
<Button icon={<UploadOutlined />}>Add File</Button>
<div style={{ display: "inline-block", marginLeft: "5px", marginRight: "5px", }}>or drag and drop file here</div>
</Upload.Dragger >
</Form.Item>更新:在之外使用表单组件,使用像name等属性对我有用。
发布于 2022-03-24 07:49:20
检查以下代码,在Form.item组件中使用规则属性
<Form.Item
name="dragger"
rules={[
{
required: true,
message: 'Please upload',
},
]}
>
<Upload.Dragger multiple>
<Button icon={<UploadOutlined />}>Add File</Button>
<div
style={{
display: 'inline-block',
marginLeft: '5px',
marginRight: '5px',
}}
>
or drag and drop file here
</div>
</Upload.Dragger>
</Form.Item>https://stackoverflow.com/questions/71598428
复制相似问题