Skip to content

Commit

Permalink
#3432 implement matching user addition case
Browse files Browse the repository at this point in the history
  • Loading branch information
jlukic committed Jan 29, 2018
1 parent 094da1c commit 0fa5821
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/definitions/modules/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2435,7 +2435,6 @@ $.fn.dropdown = function(parameters) {
var
escapedValue = module.escape.value(value),
hasInput = ($input.length > 0),
isAddition = !module.has.value(value),

This comment has been minimized.

Copy link
@jlukic

jlukic Jan 29, 2018

Author Member

This variable isnt used

currentValue = module.get.values(),
stringValue = (value !== undefined)
? String(value)
Expand Down Expand Up @@ -2538,8 +2537,8 @@ $.fn.dropdown = function(parameters) {
module.save.remoteData(selectedText, selectedValue);
}
if(settings.useLabels) {
module.add.value(selectedValue, selectedText, $selected);
module.add.label(selectedValue, selectedText, shouldAnimate);
module.add.value(selectedValue, selectedText, $selected);
module.set.activeItem($selected);
module.filterActive();
module.select.nextAvailable($selectedItem);
Expand Down Expand Up @@ -2587,8 +2586,8 @@ $.fn.dropdown = function(parameters) {
;
$label = settings.onLabelCreate.call($label, escapedValue, text);

if(module.has.label(value)) {
module.debug('Label already exists, skipping', escapedValue);
if(module.has.value(value)) {

This comment has been minimized.

Copy link
@ngouy

ngouy Feb 22, 2018

Finally found out my issue origin.
This is a breaking change.
The wrapping function (module.add.label) is trying to adding a label, and this is no more checking if this one already exists but now just checking if the value is present. The value can be present without the label. And so this function no more always adding the label when it is not present in the dom...

module.debug('User selection already exists, skipping', escapedValue);
return;
}
if(settings.label.variation) {
Expand Down Expand Up @@ -2727,6 +2726,10 @@ $.fn.dropdown = function(parameters) {
currentValue = module.get.values(),
newValue
;
if(module.has.value(addedValue)) {
module.debug('Value already selected');
return;
}
if(addedValue === '') {
module.debug('Cannot select blank values from multiselect');
return;
Expand Down Expand Up @@ -3058,6 +3061,12 @@ $.fn.dropdown = function(parameters) {
return (module.get.query() !== '');
},
value: function(value) {
return (settings.ignoreAdditionCase)
? module.has.valueIgnoringCase(value)
: module.has.valueMatchingCase(value)
;
},
valueMatchingCase: function(value) {
var
values = module.get.values(),
hasValue = $.isArray(values)
Expand All @@ -3068,6 +3077,22 @@ $.fn.dropdown = function(parameters) {
? true
: false
;
},
valueIgnoringCase: function(value) {
var
values = module.get.values(),
hasValue = false
;
if(!$.isArray(values)) {
values = [values];
}
$.each(values, function(index, existingValue) {
if(String(value).toLowerCase() == String(existingValue).toLowerCase()) {
hasValue = true;
return false;
}
});
return hasValue;
}
},

Expand Down Expand Up @@ -3669,7 +3694,8 @@ $.fn.dropdown.settings = {
forceSelection : true, // force a choice on blur with search selection

allowAdditions : false, // whether multiple select should allow user added values
hideAdditions : true, // whether or not to hide special message prompting a user they can enter a value
ignoreAdditionCase : true, // whether to ignore case when adding a user selection
hideAdditions : true, // whether or not to hide special message prompting a user they can enter a value

maxSelections : false, // When set to a number limits the number of selections to this count
useLabels : true, // whether multiple select should filter currently active selections from choices
Expand Down

1 comment on commit 0fa5821

@jbwl
Copy link

@jbwl jbwl commented on 0fa5821 Feb 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit seems to break multiple search selection inputs. Existing values (in the value tag of the input) do not display at all.
#6123

Please sign in to comment.