Skip to content

Commit

Permalink
fix(dropdown): using different keyname for fields.values failed
Browse files Browse the repository at this point in the history
When calling templates.menu(), the object passed always has a single fixed key values.
However, the implementation of templates.menu() reads the object with the configurable key fields.values.
So if a key other then values is configured, this will fail.
  • Loading branch information
WardLootens authored Aug 17, 2020
1 parent 04eca76 commit 7225780
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/definitions/modules/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,9 @@ $.fn.dropdown = function(parameters) {
values = [];
}
module.remove.message();
module.setup.menu({
values: values
});
var menuConfig = {};
menuConfig[fields.values] = values;
module.setup.menu(menuConfig);

if(values.length===0 && !settings.allowAdditions) {
module.add.message(message.noResults);
Expand Down Expand Up @@ -1008,7 +1008,9 @@ $.fn.dropdown = function(parameters) {
module.clear();
}
module.debug('Creating dropdown with specified values', values);
module.setup.menu({values: values});
var menuConfig = {};
menuConfig[fields.values] = values;
module.setup.menu(menuConfig);
$.each(values, function(index, item) {
if(item.selected == true) {
module.debug('Setting initial selection to', item[fields.value]);
Expand Down Expand Up @@ -1981,9 +1983,9 @@ $.fn.dropdown = function(parameters) {
selectValues: function() {
var
select = {},
oldGroup = []
oldGroup = [],
values = []
;
select.values = [];
$module
.find('option')
.each(function() {
Expand All @@ -2004,14 +2006,14 @@ $.fn.dropdown = function(parameters) {
}
else {
if(group.length !== oldGroup.length || group[0] !== oldGroup[0]) {
select.values.push({
values.push({
type: 'header',
divider: settings.headerDivider,
name: group.attr('label') || ''
});
oldGroup = group;
}
select.values.push({
values.push({
name : name,
value : value,
text : text,
Expand All @@ -2026,19 +2028,21 @@ $.fn.dropdown = function(parameters) {
}
if(settings.sortSelect) {
if(settings.sortSelect === true) {
select.values.sort(function(a, b) {
values.sort(function(a, b) {
return a.name.localeCompare(b.name);
});
} else if(settings.sortSelect === 'natural') {
select.values.sort(function(a, b) {
values.sort(function(a, b) {
return (a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
});
} else if($.isFunction(settings.sortSelect)) {
select.values.sort(settings.sortSelect);
values.sort(settings.sortSelect);
}
select[fields.values] = values;
module.debug('Retrieved and sorted values from select', select);
}
else {
select[fields.values] = values;
module.debug('Retrieved values from select', select);
}
return select;
Expand Down

0 comments on commit 7225780

Please sign in to comment.