diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index a38ea8ae6..eb5d3607e 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -21,6 +21,7 @@ - **API** - `cache: 'local'` would not return the localstorage cached results in some cases - **Dropdown** - `search selection` would not let you move back in an entered search string with left arrow #3596 **Thanks @Sanjo** - **Divider** - Descenders like "g" are cut off in `horizontal divider` #3585 +- **Dropdown** - `forceSelection` will now automatically select values with multi dropdowns. When using `userAdditions` setting it will now automatically tokenize the current entered value - **Form Validation / Dropdown** - Using "enter" key in a `search dropdown` could cause a form to be submitted #3676 - **Form Validation** - Revalidating a field `on: blur` could cause fields not yet interacted with to be validated #3606 - **Rail** - Fixed incorrect width for `close rail` and `very close rail` caused by variable addition with mixed units `px` + `em` #3835 diff --git a/src/definitions/modules/dropdown.js b/src/definitions/modules/dropdown.js index cba76be1e..b7ef6e72a 100644 --- a/src/definitions/modules/dropdown.js +++ b/src/definitions/modules/dropdown.js @@ -434,12 +434,12 @@ $.fn.dropdown = function(parameters) { ; if( module.can.show() && !module.is.active() ) { module.debug('Showing dropdown'); - if(module.is.multiple() && !module.has.search() && module.is.allFiltered()) { - return true; - } if(module.has.message() && !(module.has.maxSelections() || module.has.allResultsFiltered()) ) { module.remove.message(); } + if(module.is.allFiltered()) { + return true; + } if(settings.onShow.call(element) !== false) { module.animate.show(function() { if( module.can.click() ) { @@ -829,11 +829,17 @@ $.fn.dropdown = function(parameters) { if( module.has.query() ) { if(hasSelected) { module.debug('Forcing partial selection to selected item', $selectedItem); - module.event.item.click.call($selectedItem); + module.event.item.click.call($selectedItem, {}, true); return; } else { - module.remove.searchTerm(); + if(settings.allowAdditions) { + module.set.selected(module.get.query()); + module.remove.searchTerm(); + } + else { + module.remove.searchTerm(); + } } } module.hide(); @@ -905,11 +911,7 @@ $.fn.dropdown = function(parameters) { pageLostFocus = (document.activeElement === this); if(!willRefocus) { if(!itemActivated && !pageLostFocus) { - if(module.is.multiple()) { - module.remove.activeLabel(); - module.hide(); - } - else if(settings.forceSelection) { + if(settings.forceSelection) { module.forceSelection(); } else { @@ -1055,7 +1057,7 @@ $.fn.dropdown = function(parameters) { }, settings.delay.hide); } }, - click: function (event) { + click: function (event, skipRefocus) { var $choice = $(this), $target = (event) @@ -1073,7 +1075,7 @@ $.fn.dropdown = function(parameters) { module.remove.userAddition(); } module.remove.searchTerm(); - if(!module.is.focusedOnSearch()) { + if(!module.is.focusedOnSearch() && !(skipRefocus == true)) { module.focusSearch(); } } @@ -1602,16 +1604,17 @@ $.fn.dropdown = function(parameters) { if(typeof values == 'string') { values = [values]; } - remoteValues = {}; $.each(values, function(index, value) { var name = module.read.remoteData(value) ; module.verbose('Restoring value from session data', name, value); - remoteValues[value] = (name) - ? name - : value - ; + if(name) { + if(!remoteValues) { + remoteValues = {}; + } + remoteValues[value] = name; + } }); } return remoteValues; @@ -1888,13 +1891,8 @@ $.fn.dropdown = function(parameters) { values: function() { // prevents callbacks from occuring on initial load module.set.initialLoad(); - if(settings.apiSettings) { - if(settings.saveRemoteData) { - module.restore.remoteValues(); - } - else { - module.clearValue(); - } + if(settings.apiSettings && settings.saveRemoteData && module.get.remoteValues()) { + module.restore.remoteValues(); } else { module.set.selected(); @@ -2751,6 +2749,7 @@ $.fn.dropdown = function(parameters) { module.debug('Label remove callback cancelled removal'); return; } + module.remove.message(); if(isUserValue) { module.remove.value(stringValue); module.remove.label(stringValue); @@ -2827,7 +2826,7 @@ $.fn.dropdown = function(parameters) { return (settings.maxSelections && module.get.selectionCount() >= settings.maxSelections); }, allResultsFiltered: function() { - let + var $normalResults = $item.not(selector.addition) ; return ($normalResults.filter(selector.unselectable).length === $normalResults.length);