Skip to content

Commit 338898a

Browse files
authored
fix(dropdown): paste values as search query
Pasting inside a search dropdown was fetched to automatically select items in 2.9.0 Unfortunately if items are not found the paste value is completely lost. Especially remote call were not possible anymore. This PR leaves the pasted text in case no items are found and put it into the search input again
1 parent dc9662f commit 338898a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/definitions/modules/dropdown.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,28 @@
10801080
paste: function (event) {
10811081
var
10821082
pasteValue = (event.originalEvent.clipboardData || window.clipboardData).getData('text'),
1083-
tokens = pasteValue.split(settings.delimiter)
1083+
tokens = pasteValue.split(settings.delimiter),
1084+
notFoundTokens = []
10841085
;
10851086
tokens.forEach(function (value) {
1086-
module.set.selected(module.escape.htmlEntities(value.trim()), null, true, true);
1087+
if (module.set.selected(module.escape.htmlEntities(value.trim()), null, true, true) === false) {
1088+
notFoundTokens.push(value);
1089+
}
10871090
});
10881091
event.preventDefault();
1092+
if (notFoundTokens.length > 0) {
1093+
var searchEl = $search[0],
1094+
startPos = searchEl.selectionStart,
1095+
endPos = searchEl.selectionEnd,
1096+
orgText = searchEl.value,
1097+
pasteText = notFoundTokens.join(settings.delimiter),
1098+
newEndPos = startPos + pasteText.length
1099+
;
1100+
$search.val(orgText.slice(0, startPos) + pasteText + orgText.slice(endPos));
1101+
searchEl.selectionStart = newEndPos;
1102+
searchEl.selectionEnd = newEndPos;
1103+
module.event.input(event);
1104+
}
10891105
},
10901106
change: function () {
10911107
if (!internalChange) {
@@ -2726,7 +2742,7 @@
27262742
? $selectedItem || module.get.itemWithAdditions(value)
27272743
: $selectedItem || module.get.item(value);
27282744
if (!$selectedItem) {
2729-
return;
2745+
return false;
27302746
}
27312747
module.debug('Setting selected menu item to', $selectedItem);
27322748
if (module.is.multiple()) {

0 commit comments

Comments
 (0)