简体   繁体   English

创建新标签时更改select2自动选择的标签

[英]Change select2 auto selected tag when creating new tag

I am using select2, I have it setup so I can create new tags if they do not exist. 我正在使用select2,我已经设置好了所以我可以创建新的标签,如果它们不存在的话。

This is all working fine, but one bug-bear I have is that the "new tag" is the automatically selected tag, this is causing a lot of bogus, accidentially created tags. 这一切都运行正常,但我遇到的一个错误是“新标签”是自动选择的标签,这导致了很多虚假的,意外创建的标签。

What I want is that the "new tag" shows at the top as it normally does, 我想要的是“新标签”像往常一样显示在顶部,

But, if there are other sub-matching options, then the closest match there should be selected, the user can then press the up arrow if they wish to create a new tag. 但是,如果存在其他子匹配选项,则应选择最接近的匹配,如果用户希望创建新标签,则可以按向上箭头。

This is what I want to appear when typing in "scrum" when the "scrums" tag already exists: 当“scrums”标签已经存在时,这就是我想在“scrum”中输入时出现的内容:

最佳选择

I know that's old, but I came up to this question while searching for something else. 我知道这已经过时了,但我在寻找其他东西的过程中遇到了这个问题。

The default behavior of auto-selection is selecting the first matching option. 自动选择的默认行为是选择第一个匹配选项。 Here, as far as I see "Scrum" comes before "Scrums" if sorting asc. 在这里,据我所知,“Scrum”出现在“Scrums”之前,如果排序asc。 That's why it selects "Scrum" (without 's' at the end). 这就是为什么它选择“Scrum”(最后没有's')。 If the newly created option was "Scrumss", and no "Scrum" was in the options, then "Scrums" would be selected by auto-select. 如果新创建的选项是“Scrumss”,并且选项中没有“Scrum”,则可以通过自动选择选择“Scrums”。

I guess you figured your issue out, but didn't want to leave a question unanswered :) 我想你想出了你的问题,但是不想留下一个未回答的问题:)

Please write a comment if that is not the issue or I got you wrong. 如果不是问题,请写评论或我弄错了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM