pro-components icon indicating copy to clipboard operation
pro-components copied to clipboard

🧐[问题]: ProFormSelect组件 mode 设置为"tags"或"multiple"时,如何限制最大选择数量

Open MorleyZhou opened this issue 2 years ago • 7 comments

🧐 问题描述

根据 Ant Design 的 Select 组件,有 maxCount 属性限制最大多选数量,但是在 ProFormSelect 中无法使用该属性。

💻 示例代码

<ProFormSelect
    name="purifierBrand"
    colProps={{ md: 12, xl: 4 }}
    label="品牌"
    request={getFilter.run}
    mode="multiple"
    debounceTime={300}
    maxCount={2}
/>

<ProFormSelect
    name="purifierBrand"
    colProps={{ md: 12, xl: 4 }}
    label="品牌"
    request={getFilter.run}
    mode="tags"
    debounceTime={300}
    fieldProps={{
      maxCount: 2,
    }}
  />

🚑 其他信息

上面两种方式均提示没有该属性 image image

MorleyZhou avatar Jan 24 '24 09:01 MorleyZhou

看看antd版本吧,antd版本可能不支持这个属性

cheneyg916 avatar Jan 24 '24 12:01 cheneyg916

<ProFormSelect
    name="purifierBrand"
    colProps={{ md: 12, xl: 4 }}
    label="品牌"
    request={getFilter.run}
    mode="multiple"
    debounceTime={300}
    fieldProps={{
       maxCount: 2,
    }}
/>

pangxzi avatar Jan 25 '24 01:01 pangxzi

maxTagCount亲测有效, 看了4.0 5.0的antd文档,都是maxTagCount这个字段,不知maxCount是哪里查到的

<ProFormSelect
    name="purifierBrand2"
    colProps={{ md: 12, xl: 4 }}
    label="品牌"
    options={[11,22,33,44,55,66,77]}
    mode='tags'
    debounceTime={300}
    fieldProps={{
      maxTagCount:2 
    }}
  />

tangxuelei avatar Jan 25 '24 07:01 tangxuelei

maxTagCount亲测有效, 看了4.0 5.0的antd文档,都是maxTagCount这个字段,不知maxCount是哪里查到的

<ProFormSelect
    name="purifierBrand2"
    colProps={{ md: 12, xl: 4 }}
    label="品牌"
    options={[11,22,33,44,55,66,77]}
    mode='tags'
    debounceTime={300}
    fieldProps={{
      maxTagCount:2 
    }}
  />

tangxuelei avatar Jan 25 '24 07:01 tangxuelei

maxTagCount亲测有效, 看了4.0 5.0的antd文档,都是maxTagCount这个字段,不知maxCount是哪里查到的

<ProFormSelect
    name="purifierBrand2"
    colProps={{ md: 12, xl: 4 }}
    label="品牌"
    options={[11,22,33,44,55,66,77]}
    mode='tags'
    debounceTime={300}
    fieldProps={{
      maxTagCount:2 
    }}
  />

这两个不一样

image

pangxzi avatar Jan 25 '24 07:01 pangxzi

看起来放到 fieldProps 里面应该就ok的

ONLY-yours avatar Jan 25 '24 08:01 ONLY-yours

版本问题,ant design 5.13.1可以使用

MorleyZhou avatar Jan 25 '24 08:01 MorleyZhou