Fix some issues with parsing blank options.

This commit is contained in:
Patrick Filler 2011-07-15 18:04:37 -04:00
parent 7778ef0cb2
commit 15a5366aad
4 changed files with 78 additions and 58 deletions

View file

@ -214,7 +214,7 @@
data = _ref[_i]; data = _ref[_i];
if (data.group) { if (data.group) {
content += this.result_add_group(data); content += this.result_add_group(data);
} else { } else if (!data.empty) {
content += this.result_add_option(data); content += this.result_add_option(data);
if (data.selected && this.is_multiple) { if (data.selected && this.is_multiple) {
this.choice_build(data); this.choice_build(data);
@ -443,7 +443,7 @@
_ref = this.results_data; _ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i]; option = _ref[_i];
if (!option.disabled) { if (!option.disabled && !option.empty) {
if (option.group) { if (option.group) {
$(option.dom_id).hide(); $(option.dom_id).hide();
} else if (!(this.is_multiple && option.selected)) { } else if (!(this.is_multiple && option.selected)) {
@ -696,21 +696,27 @@
}; };
OptionsParser.prototype.add_option = function(option, group_id, group_disabled) { OptionsParser.prototype.add_option = function(option, group_id, group_disabled) {
var _ref; var _ref;
if (option.nodeName === "OPTION" && (this.sel_index > 0 || option.text !== "")) { if (option.nodeName === "OPTION") {
if (group_id || group_id === 0) { if (option.text !== "") {
this.parsed[group_id].children += 1; if (group_id || group_id === 0) {
this.parsed[group_id].children += 1;
}
this.parsed.push({
id: this.sel_index + this.group_index,
select_index: this.sel_index,
value: option.value,
text: option.text,
selected: option.selected,
disabled: (_ref = group_disabled === true) != null ? _ref : {
group_disabled: option.disabled
},
group_id: group_id
});
} else {
this.parsed.push({
empty: true
});
} }
this.parsed.push({
id: this.sel_index + this.group_index,
select_index: this.sel_index,
value: option.value,
text: option.text,
selected: option.selected,
disabled: (_ref = group_disabled === true) != null ? _ref : {
group_disabled: option.disabled
},
group_id: group_id
});
return this.sel_index += 1; return this.sel_index += 1;
} }
}; };

View file

@ -211,7 +211,7 @@
data = _ref[_i]; data = _ref[_i];
if (data.group) { if (data.group) {
content += this.result_add_group(data); content += this.result_add_group(data);
} else { } else if (!data.empty) {
content += this.result_add_option(data); content += this.result_add_option(data);
if (data.selected && this.is_multiple) { if (data.selected && this.is_multiple) {
this.choice_build(data); this.choice_build(data);
@ -447,7 +447,7 @@
_ref = this.results_data; _ref = this.results_data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
option = _ref[_i]; option = _ref[_i];
if (!option.disabled) { if (!option.disabled && !option.empty) {
if (option.group) { if (option.group) {
$(option.dom_id).hide(); $(option.dom_id).hide();
} else if (!(this.is_multiple && option.selected)) { } else if (!(this.is_multiple && option.selected)) {
@ -715,21 +715,27 @@
}; };
OptionsParser.prototype.add_option = function(option, group_id, group_disabled) { OptionsParser.prototype.add_option = function(option, group_id, group_disabled) {
var _ref; var _ref;
if (option.nodeName === "OPTION" && (this.sel_index > 0 || option.text !== "")) { if (option.nodeName === "OPTION") {
if (group_id || group_id === 0) { if (option.text !== "") {
this.parsed[group_id].children += 1; if (group_id || group_id === 0) {
this.parsed[group_id].children += 1;
}
this.parsed.push({
id: this.sel_index + this.group_index,
select_index: this.sel_index,
value: option.value,
text: option.text,
selected: option.selected,
disabled: (_ref = group_disabled === true) != null ? _ref : {
group_disabled: option.disabled
},
group_id: group_id
});
} else {
this.parsed.push({
empty: true
});
} }
this.parsed.push({
id: this.sel_index + this.group_index,
select_index: this.sel_index,
value: option.value,
text: option.text,
selected: option.selected,
disabled: (_ref = group_disabled === true) != null ? _ref : {
group_disabled: option.disabled
},
group_id: group_id
});
return this.sel_index += 1; return this.sel_index += 1;
} }
}; };

View file

@ -189,7 +189,7 @@ class Chosen
for data in @results_data for data in @results_data
if data.group if data.group
content += this.result_add_group data content += this.result_add_group data
else else if !data.empty
content += this.result_add_option data content += this.result_add_option data
if data.selected and @is_multiple if data.selected and @is_multiple
this.choice_build data this.choice_build data
@ -397,7 +397,7 @@ class Chosen
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i') zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
for option in @results_data for option in @results_data
if not option.disabled if not option.disabled and not option.empty
if option.group if option.group
$(option.dom_id).hide() $(option.dom_id).hide()
else if not (@is_multiple and option.selected) else if not (@is_multiple and option.selected)
@ -597,17 +597,21 @@ class OptionsParser
@group_index += 1 @group_index += 1
add_option: (option, group_id, group_disabled) -> add_option: (option, group_id, group_disabled) ->
if option.nodeName is "OPTION" and (@sel_index > 0 or option.text != "") if option.nodeName is "OPTION"
if group_id || group_id is 0 if option.text != ""
@parsed[group_id].children += 1 if group_id || group_id is 0
@parsed.push @parsed[group_id].children += 1
id: @sel_index + @group_index @parsed.push
select_index: @sel_index id: @sel_index + @group_index
value: option.value select_index: @sel_index
text: option.text value: option.value
selected: option.selected text: option.text
disabled: ((group_disabled is true) ? group_disabled : option.disabled) selected: option.selected
group_id: group_id disabled: ((group_disabled is true) ? group_disabled : option.disabled)
group_id: group_id
else
@parsed.push
empty: true
@sel_index += 1 @sel_index += 1
OptionsParser.select_to_array = (select) -> OptionsParser.select_to_array = (select) ->

View file

@ -184,7 +184,7 @@ class Chosen
for data in @results_data for data in @results_data
if data.group if data.group
content += this.result_add_group data content += this.result_add_group data
else else if !data.empty
content += this.result_add_option data content += this.result_add_option data
if data.selected and @is_multiple if data.selected and @is_multiple
this.choice_build data this.choice_build data
@ -389,7 +389,7 @@ class Chosen
zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i') zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i')
for option in @results_data for option in @results_data
if not option.disabled if not option.disabled and not option.empty
if option.group if option.group
$(option.dom_id).hide() $(option.dom_id).hide()
else if not (@is_multiple and option.selected) else if not (@is_multiple and option.selected)
@ -595,17 +595,21 @@ class OptionsParser
@group_index += 1 @group_index += 1
add_option: (option, group_id, group_disabled) -> add_option: (option, group_id, group_disabled) ->
if option.nodeName is "OPTION" and (@sel_index > 0 or option.text != "") if option.nodeName is "OPTION"
if group_id || group_id is 0 if option.text != ""
@parsed[group_id].children += 1 if group_id || group_id is 0
@parsed.push @parsed[group_id].children += 1
id: @sel_index + @group_index @parsed.push
select_index: @sel_index id: @sel_index + @group_index
value: option.value select_index: @sel_index
text: option.text value: option.value
selected: option.selected text: option.text
disabled: ((group_disabled is true) ? group_disabled : option.disabled) selected: option.selected
group_id: group_id disabled: ((group_disabled is true) ? group_disabled : option.disabled)
group_id: group_id
else
@parsed.push
empty: true
@sel_index += 1 @sel_index += 1
OptionsParser.select_to_array = (select) -> OptionsParser.select_to_array = (select) ->