【问题标题】:Remove default value from Ant Design Select dropdown从 Ant Design 选择下拉列表中删除默认值
【发布时间】:2022-12-18 13:25:24
【问题描述】:

我正在使用 Ant Design <Form.Item> 来显示类别列表。有没有办法删除默认选择的值。

          <Form.Item
                  label='Description'
                  name='description'
                  // rules={[{ required: true, message: 'This field is mandatory' }]}
                >
                  <Form.Item name='description'>
                    <Typography.Text type='secondary'>
                      Let your attendees know what to expect, including the agenda, what they need to bring, and how to
                      find the group.
                    </Typography.Text>
                    <ReactQuill theme='snow' value={description} onChange={setDescription} />
                  </Form.Item>
                </Form.Item>

                <Form.Item label='Category' name='category'>
                  <Select
                    mode='multiple'
                    bordered={false}
                    placeholder='Select category'
                    onChange={(value) => setSelectedCategories(value)}
                    style={{ backgroundColor: 'white', padding: '5px', border: '1px solid #999db6' }}
                    
                  >
                    {categories?.map((categories, indexValue) => (
                      <Select.Option
                        key={indexValue}
                        value={categories.key}
                        
                        disabled={
                          selectedCategories?.length === 5 && !selectedCategories?.includes(categories.key) && true
                        }
                      >
                        {categories.value}
                      </Select.Option>
                    ))}
                  </Select>
                </Form.Item>

我得到一个我无法删除的默认值(见图),我尝试使用 defaultValue={disable} on 但无济于事。我错过了什么?

【问题讨论】:

    标签: typescript antd categories


    【解决方案1】:

    Form.Item提供房产initialValue。但是,如果您不设置它,默认情况下它应该是未定义的,也许您可​​以提供一个最小的工作代码和框,我可以看一下。

    <Form.Item 
      label='Category' 
      name='category'
      initialValue={undefined} //should be undefined by default
    >
    ...
    </Form.Item>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      相关资源
      最近更新 更多