Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 34d1fb1

Browse files
committed
fix(ng_model_select): IE has its own way of handling options
1 parent 5af8843 commit 34d1fb1

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

lib/directive/ng_model_select.dart

+19-13
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class _SingleSelectMode extends _SelectMode {
164164
dom.SelectElement select,
165165
NgModel model,
166166
this._nullOption)
167-
: _unknownOption = new dom.OptionElement(value: '?'),
167+
: _unknownOption = new dom.OptionElement(value: '?', selected: true),
168168
super(options, select, model);
169169

170170
void onViewChange(_) {
@@ -178,31 +178,37 @@ class _SingleSelectMode extends _SelectMode {
178178
}
179179

180180
void onModelChange(value) {
181-
bool found = false;
181+
bool anySelected = false;
182+
var optionsToUnselect =[];
182183
_forEachOption((option, i) {
183-
if (option == _unknownOption) return;
184+
if (identical(option, _unknownOption)) return;
184185
var selected;
185186
if (value == null) {
186-
selected = option == _nullOption;
187+
selected = identical(option, _nullOption);
187188
} else {
188189
OptionValue optionValue = options[option];
189190
selected = optionValue == null ? false : optionValue.ngValue == value;
190191
}
191-
found = found || selected;
192+
anySelected = anySelected || selected;
192193
option.selected = selected;
194+
if (!selected) optionsToUnselect.add(option);
193195
});
194196

195-
if (!found) {
196-
if (!_unknownOptionActive) {
197-
select.insertBefore(_unknownOption, select.firstChild);
198-
_unknownOption.selected = true;
199-
_unknownOptionActive = true;
200-
}
201-
} else {
202-
if (_unknownOptionActive) {
197+
if (anySelected) {
198+
if (_unknownOptionActive == true) {
203199
_unknownOption.remove();
204200
_unknownOptionActive = false;
205201
}
202+
} else {
203+
if (_unknownOptionActive == false) {
204+
_unknownOptionActive = true;
205+
select.insertBefore(_unknownOption, select.firstChild);
206+
}
207+
// It seems that IE do not allow having no option selected. It could then happen that an
208+
// option remains selected after the previous loop. Also IE does not enforce that only one
209+
// option is selected so we un-select options again to end up with a single selection.
210+
_unknownOption.selected = true;
211+
for (var option in optionsToUnselect) option.selected = false;
206212
}
207213
}
208214
}

0 commit comments

Comments
 (0)