Browse Source

Fixes #355 #359 #277 Issue with improper type check on dropdown default values

pull/367/head
jlukic 11 years ago
parent
commit
c5a8f7ee69
1 changed files with 19 additions and 6 deletions
  1. 25
      src/modules/dropdown.js

25
src/modules/dropdown.js

@ -210,8 +210,12 @@ $.fn.dropdown = function(parameters) {
click: function (event) { click: function (event) {
var var
$choice = $(this), $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 ) { if( $choice.find(selector.menu).size() === 0 ) {
module.determine.selectAction(text, value); module.determine.selectAction(text, value);
@ -322,15 +326,21 @@ $.fn.dropdown = function(parameters) {
; ;
value = (value !== undefined) value = (value !== undefined)
? value ? value
: ( module.get.value() || module.get.text() )
: ( module.get.value() !== undefined)
? module.get.value()
: module.get.text()
; ;
if(value) { if(value) {
$item $item
.each(function() { .each(function() {
var var
$choice = $(this), $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 ) { if( optionValue == value || optionText == value ) {
$selectedItem = $(this); $selectedItem = $(this);
@ -369,7 +379,10 @@ $.fn.dropdown = function(parameters) {
; ;
if($selectedItem) { if($selectedItem) {
module.debug('Setting selected menu item to', $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 $item
.removeClass(className.active) .removeClass(className.active)
; ;

Loading…
Cancel
Save