Skip to content

Commit

Permalink
fix(dropdown): paste values as search query
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lubber-de authored Jan 16, 2023
1 parent dc9662f commit 338898a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/definitions/modules/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,12 +1080,28 @@
paste: function (event) {
var
pasteValue = (event.originalEvent.clipboardData || window.clipboardData).getData('text'),
tokens = pasteValue.split(settings.delimiter)
tokens = pasteValue.split(settings.delimiter),
notFoundTokens = []
;
tokens.forEach(function (value) {
module.set.selected(module.escape.htmlEntities(value.trim()), null, true, true);
if (module.set.selected(module.escape.htmlEntities(value.trim()), null, true, true) === false) {
notFoundTokens.push(value);
}
});
event.preventDefault();
if (notFoundTokens.length > 0) {
var searchEl = $search[0],
startPos = searchEl.selectionStart,
endPos = searchEl.selectionEnd,
orgText = searchEl.value,
pasteText = notFoundTokens.join(settings.delimiter),
newEndPos = startPos + pasteText.length
;
$search.val(orgText.slice(0, startPos) + pasteText + orgText.slice(endPos));
searchEl.selectionStart = newEndPos;
searchEl.selectionEnd = newEndPos;
module.event.input(event);
}
},
change: function () {
if (!internalChange) {
Expand Down Expand Up @@ -2726,7 +2742,7 @@
? $selectedItem || module.get.itemWithAdditions(value)
: $selectedItem || module.get.item(value);
if (!$selectedItem) {
return;
return false;
}
module.debug('Setting selected menu item to', $selectedItem);
if (module.is.multiple()) {
Expand Down

0 comments on commit 338898a

Please sign in to comment.