From c5a8f7ee698f45ea9cdcb319a5b408beefa1aa0a Mon Sep 17 00:00:00 2001 From: jlukic Date: Sat, 16 Nov 2013 22:32:43 -0500 Subject: [PATCH] Fixes #355 #359 #277 Issue with improper type check on dropdown default values --- src/modules/dropdown.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index 62c01935c..ad046c44a 100755 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -210,8 +210,12 @@ $.fn.dropdown = function(parameters) { click: function (event) { var $choice = $(this), - text = $choice.data(metadata.text) || $choice.text(), - value = $choice.data(metadata.value) || text.toLowerCase() + text = ( $choice.data(metadata.text) !== undefined ) + ? $choice.data(metadata.text) + : $choice.text(), + value = ( $choice.data(metadata.value) !== undefined) + ? $choice.data(metadata.value) + : text.toLowerCase() ; if( $choice.find(selector.menu).size() === 0 ) { module.determine.selectAction(text, value); @@ -322,15 +326,21 @@ $.fn.dropdown = function(parameters) { ; value = (value !== undefined) ? value - : ( module.get.value() || module.get.text() ) + : ( module.get.value() !== undefined) + ? module.get.value() + : module.get.text() ; if(value) { $item .each(function() { var $choice = $(this), - optionText = $choice.data(metadata.text) || $choice.text(), - optionValue = $choice.data(metadata.value) || optionText.toLowerCase() + optionText = ( $choice.data(metadata.text) !== undefined ) + ? $choice.data(metadata.text) + : $choice.text(), + optionValue = ( $choice.data(metadata.value) !== undefined ) + ? $choice.data(metadata.value) + : optionText.toLowerCase() ; if( optionValue == value || optionText == value ) { $selectedItem = $(this); @@ -369,7 +379,10 @@ $.fn.dropdown = function(parameters) { ; if($selectedItem) { module.debug('Setting selected menu item to', $selectedItem); - selectedText = $selectedItem.data(metadata.text) || $selectedItem.text(); + selectedText = ($selectedItem.data(metadata.text) !== undefined) + ? $selectedItem.data(metadata.text) + : $selectedItem.text() + ; $item .removeClass(className.active) ;