aboutsummaryrefslogtreecommitdiffstats
path: root/src/widgets.js
diff options
context:
space:
mode:
authorIgor Minar2011-09-14 04:32:16 +0200
committerIgor Minar2011-09-16 02:44:30 +0200
commit555f4152909e1c0bd5400737a62dc5d63ecd32d3 (patch)
treec0a52032d325133df9cdeac31202caf6a1320cfb /src/widgets.js
parent3800d177030d20c5c3d04e3601f892c46e723dc2 (diff)
downloadangular.js-555f4152909e1c0bd5400737a62dc5d63ecd32d3.tar.bz2
fix(ng:options): fix selecting options
Contains 3 fixes: - the internal model was by mistake using "checked" property instead of "selected" - use jqLite.prop() to set 'selected' property - added inChangeEvent check - we should not interfere with the browser selecting elements when not necessary
Diffstat (limited to 'src/widgets.js')
-rw-r--r--src/widgets.js16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/widgets.js b/src/widgets.js
index b0430b95..f0376422 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -716,7 +716,8 @@ angularWidget('select', function(element){
// optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
var optionGroupsCache = [[{element: selectElement, label:''}]],
scope = this,
- model = modelAccessor(scope, element);
+ model = modelAccessor(scope, element),
+ inChangeEvent;
// find existing special options
forEach(selectElement.children(), function(option){
@@ -733,6 +734,12 @@ angularWidget('select', function(element){
tempScope = scope.$new(),
value, optionElement, index, groupIndex, length, groupLength;
+ // let's set a flag that the current model change is due to a change event.
+ // the default action of option selection will cause the appropriate option element to be
+ // deselected and another one to be selected - there is no need for us to be updating the DOM
+ // in this case.
+ inChangeEvent = true;
+
try {
if (isMultiselect) {
value = [];
@@ -768,6 +775,7 @@ angularWidget('select', function(element){
scope.$root.$apply();
} finally {
tempScope = null; // TODO(misko): needs to be $destroy
+ inChangeEvent = false;
}
});
@@ -886,8 +894,8 @@ angularWidget('select', function(element){
if (existingOption.id !== option.id) {
lastElement.val(existingOption.id = option.id);
}
- if (existingOption.selected !== option.selected) {
- lastElement.attr('selected', option.selected);
+ if (!inChangeEvent && existingOption.selected !== option.selected) {
+ lastElement.prop('selected', (existingOption.selected = option.selected));
}
} else {
// grow elements
@@ -902,7 +910,7 @@ angularWidget('select', function(element){
element: element,
label: option.label,
id: option.id,
- checked: option.selected
+ selected: option.selected
});
if (lastElement) {
lastElement.after(element);