refactor(select, ngOptions): extract common methods; make consistent
This commit is contained in:
committed by
Martin Staffa
parent
4b06637f70
commit
ff0e61166d
@@ -449,12 +449,12 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
|
||||
if (!multiple) {
|
||||
|
||||
selectCtrl.writeValue = function writeNgOptionsValue(value) {
|
||||
var selectedOption = options.selectValueMap[selectElement.val()];
|
||||
var selectedOption = selectElement[0].options[selectElement[0].selectedIndex];
|
||||
var option = options.getOptionFromViewValue(value);
|
||||
|
||||
// Make sure to remove the selected attribute from the previously selected option
|
||||
// Otherwise, screen readers might get confused
|
||||
if (selectedOption) selectedOption.element.removeAttribute('selected');
|
||||
if (selectedOption) selectedOption.removeAttribute('selected');
|
||||
|
||||
if (option) {
|
||||
// Don't update the option when it is already selected.
|
||||
@@ -464,7 +464,6 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
|
||||
|
||||
if (selectElement[0].value !== option.selectValue) {
|
||||
selectCtrl.removeUnknownOption();
|
||||
selectCtrl.unselectEmptyOption();
|
||||
|
||||
selectElement[0].value = option.selectValue;
|
||||
option.element.selected = true;
|
||||
@@ -472,15 +471,7 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
|
||||
|
||||
option.element.setAttribute('selected', 'selected');
|
||||
} else {
|
||||
|
||||
if (value == null && providedEmptyOption) {
|
||||
selectCtrl.removeUnknownOption();
|
||||
selectCtrl.selectEmptyOption();
|
||||
} else if (selectCtrl.unknownOption.parent().length) {
|
||||
selectCtrl.updateUnknownOption(value);
|
||||
} else {
|
||||
selectCtrl.renderUnknownOption(value);
|
||||
}
|
||||
selectCtrl.selectUnknownOrEmptyOption(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ var SelectController =
|
||||
|
||||
self.unselectEmptyOption = function() {
|
||||
if (self.hasEmptyOption) {
|
||||
self.emptyOption.removeAttr('selected');
|
||||
setOptionSelectedStatus(self.emptyOption, false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -128,14 +128,7 @@ var SelectController =
|
||||
var selectedOption = $element[0].options[$element[0].selectedIndex];
|
||||
setOptionSelectedStatus(jqLite(selectedOption), true);
|
||||
} else {
|
||||
if (value == null && self.emptyOption) {
|
||||
self.removeUnknownOption();
|
||||
self.selectEmptyOption();
|
||||
} else if (self.unknownOption.parent().length) {
|
||||
self.updateUnknownOption(value);
|
||||
} else {
|
||||
self.renderUnknownOption(value);
|
||||
}
|
||||
self.selectUnknownOrEmptyOption(value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -178,6 +171,16 @@ var SelectController =
|
||||
return !!optionsMap.get(value);
|
||||
};
|
||||
|
||||
self.selectUnknownOrEmptyOption = function(value) {
|
||||
if (value == null && self.emptyOption) {
|
||||
self.removeUnknownOption();
|
||||
self.selectEmptyOption();
|
||||
} else if (self.unknownOption.parent().length) {
|
||||
self.updateUnknownOption(value);
|
||||
} else {
|
||||
self.renderUnknownOption(value);
|
||||
}
|
||||
};
|
||||
|
||||
var renderScheduled = false;
|
||||
function scheduleRender() {
|
||||
|
||||
Reference in New Issue
Block a user