[英]On removing selected item(using backspace), dropdown list is displaying the removed item only in select2 rails
I have a multi-select, select2 dropdown in rails.我在rails中有一个多选的select2下拉菜单。 Currently when I select some 2-3 options from the lis and when i click on backspace the selected element is getting deleted and the dropdown list with all the options are getting displayed.目前,当我 select 来自 lis 的一些 2-3 个选项时,当我单击退格键时,所选元素被删除,并且所有选项的下拉列表都被显示。 But when I type some initials and then select from the list and then click on backspace the dropdown list is populating the just deleted option.但是当我从列表中输入一些首字母,然后 select 然后单击退格键时,下拉列表正在填充刚刚删除的选项。 Is there a way where in on typing and then selecting, the dropdown list will display the full list upon clicking on backspace??有没有办法在输入然后选择时,下拉列表将在单击退格键时显示完整列表? The code that I am using is(according to https://github.com/select2/select2/issues/3354#issuecomment-132389291 ):我使用的代码是(根据https://github.com/select2/select2/issues/3354#issuecomment-132389291 ):
$.fn.select2.amd.require(['select2/selection/search'], function (Search) {
var oldRemoveChoice = Search.prototype.searchRemoveChoice;
Search.prototype.searchRemoveChoice = function () {
oldRemoveChoice.apply(this, arguments);
this.$search.val('');
};
$.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
$('#reports_employee_id').select2({
matcher: oldMatcher(matchStart),
templateResult: formatSearch,
templateSelection: formatSelected,
maximumSelectionLength: 25,
placeholder: " "
})
});
});
Thanks In Advance !!提前致谢 !!
Ok I understood the problem to this.好的,我理解这个问题。 I needed to handle the change.Below I am attaching the updated code for reference.我需要处理更改。下面我附上更新的代码以供参考。
$.fn.select2.amd.require(['select2/selection/search'], function (Search) {
var oldRemoveChoice = Search.prototype.searchRemoveChoice;
Search.prototype.searchRemoveChoice = function () {
oldRemoveChoice.apply(this, arguments);
this.$search.val('');
this.handleSearch();
};
$.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
$('#reports_employee_id').select2({
matcher: oldMatcher(matchStart),
templateResult: formatSearch,
templateSelection: formatSelected,
maximumSelectionLength: 25,
placeholder: " "
})
});
});
Just needed add this line:只需要添加这一行:
this.handleSearch();
and it works as expected.它按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.