mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 23:34:42 +00:00
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
This commit is contained in:
parent
3800d17703
commit
555f415290
1 changed files with 12 additions and 4 deletions
|
|
@ -716,7 +716,8 @@ angularWidget('select', function(element){
|
||||||
// optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
|
// optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
|
||||||
var optionGroupsCache = [[{element: selectElement, label:''}]],
|
var optionGroupsCache = [[{element: selectElement, label:''}]],
|
||||||
scope = this,
|
scope = this,
|
||||||
model = modelAccessor(scope, element);
|
model = modelAccessor(scope, element),
|
||||||
|
inChangeEvent;
|
||||||
|
|
||||||
// find existing special options
|
// find existing special options
|
||||||
forEach(selectElement.children(), function(option){
|
forEach(selectElement.children(), function(option){
|
||||||
|
|
@ -733,6 +734,12 @@ angularWidget('select', function(element){
|
||||||
tempScope = scope.$new(),
|
tempScope = scope.$new(),
|
||||||
value, optionElement, index, groupIndex, length, groupLength;
|
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 {
|
try {
|
||||||
if (isMultiselect) {
|
if (isMultiselect) {
|
||||||
value = [];
|
value = [];
|
||||||
|
|
@ -768,6 +775,7 @@ angularWidget('select', function(element){
|
||||||
scope.$root.$apply();
|
scope.$root.$apply();
|
||||||
} finally {
|
} finally {
|
||||||
tempScope = null; // TODO(misko): needs to be $destroy
|
tempScope = null; // TODO(misko): needs to be $destroy
|
||||||
|
inChangeEvent = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -886,8 +894,8 @@ angularWidget('select', function(element){
|
||||||
if (existingOption.id !== option.id) {
|
if (existingOption.id !== option.id) {
|
||||||
lastElement.val(existingOption.id = option.id);
|
lastElement.val(existingOption.id = option.id);
|
||||||
}
|
}
|
||||||
if (existingOption.selected !== option.selected) {
|
if (!inChangeEvent && existingOption.selected !== option.selected) {
|
||||||
lastElement.attr('selected', option.selected);
|
lastElement.prop('selected', (existingOption.selected = option.selected));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// grow elements
|
// grow elements
|
||||||
|
|
@ -902,7 +910,7 @@ angularWidget('select', function(element){
|
||||||
element: element,
|
element: element,
|
||||||
label: option.label,
|
label: option.label,
|
||||||
id: option.id,
|
id: option.id,
|
||||||
checked: option.selected
|
selected: option.selected
|
||||||
});
|
});
|
||||||
if (lastElement) {
|
if (lastElement) {
|
||||||
lastElement.after(element);
|
lastElement.after(element);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue