check by count

pull/6874/head
raivaibhav 5 years ago
parent ace6bc0354
commit 08fc888515

@ -534,17 +534,17 @@ export function set_style(node, key, value, important) {
} }
export function select_option(select, value) { export function select_option(select, value) {
let have_select_attr = false; let count_selected_attr = 0;
for (let i = 0; i < select.options.length; i += 1) { for (let i = 0; i < select.options.length; i += 1) {
const option = select.options[i]; const option = select.options[i];
if (option.hasAttribute('selected')) have_select_attr = true; if (option.hasAttribute('selected')) count_selected_attr++;
if (option.__value === value) { if (option.__value === value) {
option.selected = true; option.selected = true;
return; return;
} }
} }
if (!have_select_attr) select.selectedIndex = -1; // no option should be selected if (count_selected_attr === 0) select.selectedIndex = -1; // no option should be selected
} }
export function select_options(select, value) { export function select_options(select, value) {

Loading…
Cancel
Save