gpt4 book ai didi

javascript - 按 Enter 正在创建标签,但将文本保留在 Select2 中

转载 作者:可可西里 更新时间:2023-11-01 12:57:15 27 4
gpt4 key购买 nike

Select2 版本:4.0.5

问题:在多标签(带有标签:true 或带有预填充标签)中,每次当我按回车键选择标签时,它都会创建标签但将文本保留在新标签的右侧,如果我在之后按另一个键它就会消失. (仅在使用 Enter 键时发生)

示例:
enter image description here

如您所见,当我键入标签并按 Enter 键时,它会创建标签(预期行为),但它会将原始文本保留在新标签的右侧...

这是正常行为吗?或者我应该怎么做?

我的 Select2 代码:

 var editorTagElement = document.createElement("select");
editorTagElement.className('myEditor');
editorTagElement.setAttribute("multiple", "multiple");
editorTagElement.style.overflow = 'auto';
editorTagElement.style.fontSize = '13px';

this.OptionsSelect2 = {};
this.OptionsSelect2.placeholder = "";
this.OptionsSelect2.language = ReturnCustomLanguage();
this.OptionsSelect2.formatNoMatches = function () {
return '';
};
this.OptionsSelect2.allowClear = true;
this.OptionsSelect2.minimumInputLength = 2;
this.OptionsSelect2.tags = true;
this.OptionsSelect2.tokenSeparators = [' '];
this.OptionsSelect2.createTag = function (params) {
var term = $.trim(params.term);
if (term.length < 2) {
return null;
}
term = term.replace(/ /g, "");
return {
id: term,
text: term,
newTag: true
}
};
this.OptionsSelect2.closeOnSelect = false;

$('.myEditor').select2(this.OptionsSelect2);

在此之后,我将编辑器附加到正文或我的 html 中的其他位置...

最佳答案

Option closeOnSelect 保留值,但它不是预期的行为。如果您将 closeOnSelect 更改为 true(默认值,只需删除代码中的 this.OptionsSelect2.closeOnSelect = false;),它将作为你期待的。

要在添加值后保持弹出窗口打开,您应该编写一个类似于 github issue 中建议的处理程序

关于javascript - 按 Enter 正在创建标签,但将文本保留在 Select2 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48096401/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com