Browse Source

Dropdown: Adds strict type checking as an option for form selection, allowing for better handling of data-value=0, value='' and other ambiguous values

pull/701/merge
jlukic 11 years ago
parent
commit
565e0a075a
2 changed files with 22 additions and 9 deletions
  1. 6
      src/modules/behavior/form.js
  2. 25
      src/modules/dropdown.js

6
src/modules/behavior/form.js

@ -107,12 +107,10 @@ $.fn.form = function(fields, parameters) {
;
$field
.each(function() {
var
var
type = $(this).prop('type'),
inputEvent = module.get.changeEvent(type)
;
if(settings.inline == true) {
}
$(this)
.on(inputEvent + eventNamespace, module.event.field.change)
;
@ -201,7 +199,7 @@ $.fn.form = function(fields, parameters) {
get: {
changeEvent: function(type) {
if(type == 'checkbox' || type == 'radio') {
if(type == 'checkbox' || type == 'radio' || type == 'hidden') {
return 'change';
}
else {

25
src/modules/dropdown.js

@ -334,7 +334,7 @@ $.fn.dropdown = function(parameters) {
: $module.data(metadata.value)
;
},
item: function(value) {
item: function(value, strict) {
var
$selectedItem = false
;
@ -344,6 +344,10 @@ $.fn.dropdown = function(parameters) {
? module.get.value()
: module.get.text()
;
strict = (value === '')
? true
: strict || false
;
if(value !== undefined) {
$item
.each(function() {
@ -358,11 +362,22 @@ $.fn.dropdown = function(parameters) {
? optionText.toLowerCase()
: optionText
;
if( optionValue == value ) {
$selectedItem = $(this);
if(strict) {
module.debug('Ambiguous dropdown value using strict type check', value);
if( optionValue === value ) {
$selectedItem = $(this);
}
else if( !$selectedItem && optionText === value ) {
$selectedItem = $(this);
}
}
else if( !$selectedItem && optionText == value ) {
$selectedItem = $(this);
else {
if( optionValue == value ) {
$selectedItem = $(this);
}
else if( !$selectedItem && optionText == value ) {
$selectedItem = $(this);
}
}
})
;

Loading…
Cancel
Save