aboutsummaryrefslogtreecommitdiffstats
path: root/src/widget/select.js
diff options
context:
space:
mode:
authorTEHEK Firefox2011-10-11 22:37:00 +0000
committerIgor Minar2011-10-19 22:52:14 -0700
commit36928858104ba793dfc7372dbaa28048123d6e63 (patch)
treea797722f18f0da73316e5660f046f336c9e0c474 /src/widget/select.js
parent5d43439dbe764a4c7227f51b34a81b044f13901b (diff)
downloadangular.js-36928858104ba793dfc7372dbaa28048123d6e63.tar.bz2
fix(ng:options): compile null/blank option tag
Fixes #562
Diffstat (limited to 'src/widget/select.js')
-rw-r--r--src/widget/select.js35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/widget/select.js b/src/widget/select.js
index 2448d40c..ba340490 100644
--- a/src/widget/select.js
+++ b/src/widget/select.js
@@ -241,10 +241,13 @@ angularWidget('select', function(element){
inChangeEvent;
// find existing special options
- forEach(selectElement.children(), function(option){
- if (option.value == '')
- // User is allowed to select the null.
- nullOption = {label:jqLite(option).text(), id:''};
+ forEach(selectElement.children(), function(option) {
+ if (option.value == '') {
+ // developer declared null option, so user should be able to select it
+ nullOption = jqLite(option).remove();
+ // compile the element since there might be bindings in it
+ compile(nullOption)(modelScope);
+ }
});
selectElement.html(''); // clear contents
@@ -314,7 +317,7 @@ angularWidget('select', function(element){
selectedSet = new HashMap(modelValue);
} else if (modelValue === null || nullOption) {
// if we are not multiselect, and we are null then we have to add the nullOption
- optionGroups[''].push(extend({selected:modelValue === null, id:'', label:''}, nullOption));
+ optionGroups[''].push({selected:modelValue === null, id:'', label:''});
selectedSet = true;
}
@@ -389,13 +392,21 @@ angularWidget('select', function(element){
}
} else {
// grow elements
- // jQuery(v1.4.2) Bug: We should be able to chain the method calls, but
- // in this version of jQuery on some browser the .text() returns a string
- // rather then the element.
- (element = optionTemplate.clone())
- .val(option.id)
- .attr('selected', option.selected)
- .text(option.label);
+
+ // if it's a null option
+ if (option.id === '' && nullOption) {
+ // put back the pre-compiled element
+ element = nullOption;
+ } else {
+ // jQuery(v1.4.2) Bug: We should be able to chain the method calls, but
+ // in this version of jQuery on some browser the .text() returns a string
+ // rather then the element.
+ (element = optionTemplate.clone())
+ .val(option.id)
+ .attr('selected', option.selected)
+ .text(option.label);
+ }
+
existingOptions.push(existingOption = {
element: element,
label: option.label,