【发布时间】:2020-07-22 19:25:06
【问题描述】:
我正在使用 ant design AutoComplete 进行位置选择。数据源是一个数组。这是我的代码。
<Form.Item
label={t("City")}
name="location"
rules={[
{
required: true,
message: t("Please enter your city"),
},
]}
>
<AutoComplete
options={this.props.cityList}
allowClear={true}
placeholder={t("Enter your city")}
className="ant-select-custom"
filterOption={(inputValue, option) =>
option.value.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1
}
/>
</Form.Item>
问题是,我可以输入任何不在数据源中的内容。我希望它限制它。如果我输入了不在数据源中的内容,则应该删除该值。我试过onBlur() 和onChange() 但没有运气。谁能帮我解决这个问题?
提前致谢
【问题讨论】:
标签: reactjs autocomplete antd