Browse Source

Fix issue with APIsettings not behaving correctly when restoring a value without session data, fixed some instances where empty message could appear with results when removing multiselect choice. Fixed forceSelection to work consistently with multiselect

pull/4074/head
Jack Lukic 9 years ago
parent
commit
5a610c35f3
2 changed files with 25 additions and 25 deletions
  1. 1
      RELEASE-NOTES.md
  2. 49
      src/definitions/modules/dropdown.js

1
RELEASE-NOTES.md

@ -21,6 +21,7 @@
- **API** - `cache: 'local'` would not return the localstorage cached results in some cases - **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** - **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 - **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 / 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 - **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 - **Rail** - Fixed incorrect width for `close rail` and `very close rail` caused by variable addition with mixed units `px` + `em` #3835

49
src/definitions/modules/dropdown.js

@ -434,12 +434,12 @@ $.fn.dropdown = function(parameters) {
; ;
if( module.can.show() && !module.is.active() ) { if( module.can.show() && !module.is.active() ) {
module.debug('Showing dropdown'); 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()) ) { if(module.has.message() && !(module.has.maxSelections() || module.has.allResultsFiltered()) ) {
module.remove.message(); module.remove.message();
} }
if(module.is.allFiltered()) {
return true;
}
if(settings.onShow.call(element) !== false) { if(settings.onShow.call(element) !== false) {
module.animate.show(function() { module.animate.show(function() {
if( module.can.click() ) { if( module.can.click() ) {
@ -829,11 +829,17 @@ $.fn.dropdown = function(parameters) {
if( module.has.query() ) { if( module.has.query() ) {
if(hasSelected) { if(hasSelected) {
module.debug('Forcing partial selection to selected item', $selectedItem); module.debug('Forcing partial selection to selected item', $selectedItem);
module.event.item.click.call($selectedItem);
module.event.item.click.call($selectedItem, {}, true);
return; return;
} }
else { else {
module.remove.searchTerm();
if(settings.allowAdditions) {
module.set.selected(module.get.query());
module.remove.searchTerm();
}
else {
module.remove.searchTerm();
}
} }
} }
module.hide(); module.hide();
@ -905,11 +911,7 @@ $.fn.dropdown = function(parameters) {
pageLostFocus = (document.activeElement === this); pageLostFocus = (document.activeElement === this);
if(!willRefocus) { if(!willRefocus) {
if(!itemActivated && !pageLostFocus) { if(!itemActivated && !pageLostFocus) {
if(module.is.multiple()) {
module.remove.activeLabel();
module.hide();
}
else if(settings.forceSelection) {
if(settings.forceSelection) {
module.forceSelection(); module.forceSelection();
} }
else { else {
@ -1055,7 +1057,7 @@ $.fn.dropdown = function(parameters) {
}, settings.delay.hide); }, settings.delay.hide);
} }
}, },
click: function (event) {
click: function (event, skipRefocus) {
var var
$choice = $(this), $choice = $(this),
$target = (event) $target = (event)
@ -1073,7 +1075,7 @@ $.fn.dropdown = function(parameters) {
module.remove.userAddition(); module.remove.userAddition();
} }
module.remove.searchTerm(); module.remove.searchTerm();
if(!module.is.focusedOnSearch()) {
if(!module.is.focusedOnSearch() && !(skipRefocus == true)) {
module.focusSearch(); module.focusSearch();
} }
} }
@ -1602,16 +1604,17 @@ $.fn.dropdown = function(parameters) {
if(typeof values == 'string') { if(typeof values == 'string') {
values = [values]; values = [values];
} }
remoteValues = {};
$.each(values, function(index, value) { $.each(values, function(index, value) {
var var
name = module.read.remoteData(value) name = module.read.remoteData(value)
; ;
module.verbose('Restoring value from session data', name, 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; return remoteValues;
@ -1888,13 +1891,8 @@ $.fn.dropdown = function(parameters) {
values: function() { values: function() {
// prevents callbacks from occuring on initial load // prevents callbacks from occuring on initial load
module.set.initialLoad(); 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 { else {
module.set.selected(); module.set.selected();
@ -2751,6 +2749,7 @@ $.fn.dropdown = function(parameters) {
module.debug('Label remove callback cancelled removal'); module.debug('Label remove callback cancelled removal');
return; return;
} }
module.remove.message();
if(isUserValue) { if(isUserValue) {
module.remove.value(stringValue); module.remove.value(stringValue);
module.remove.label(stringValue); module.remove.label(stringValue);
@ -2827,7 +2826,7 @@ $.fn.dropdown = function(parameters) {
return (settings.maxSelections && module.get.selectionCount() >= settings.maxSelections); return (settings.maxSelections && module.get.selectionCount() >= settings.maxSelections);
}, },
allResultsFiltered: function() { allResultsFiltered: function() {
let
var
$normalResults = $item.not(selector.addition) $normalResults = $item.not(selector.addition)
; ;
return ($normalResults.filter(selector.unselectable).length === $normalResults.length); return ($normalResults.filter(selector.unselectable).length === $normalResults.length);

Loading…
Cancel
Save