From bcbb6e2ba33a68991ae9ba96685c7619eef4b9d3 Mon Sep 17 00:00:00 2001 From: YusukeIwaki Date: Wed, 29 Jun 2022 09:57:29 +0900 Subject: [PATCH] fix: parse empty options in element.'); } - const options = Array.from(element.options); - element.value = undefined; - for (const option of options) { - option.selected = values.includes(option.value); - if (option.selected && !element.multiple) { - break; + const selectedValues = new Set(); + if (!element.multiple) { + for (const option of element.options) { + option.selected = false; + } + for (const option of element.options) { + if (values.has(option.value)) { + option.selected = true; + selectedValues.add(option.value); + break; + } + } + } else { + for (const option of element.options) { + option.selected = values.has(option.value); + if (option.selected) { + selectedValues.add(option.value); + } } } element.dispatchEvent(new Event('input', { bubbles: true })); element.dispatchEvent(new Event('change', { bubbles: true })); - return options.filter(option => option.selected).map(option => option.value); + return [...selectedValues.values()]; } JAVASCRIPT evaluate(fn, values) diff --git a/spec/assets/input/select.html b/spec/assets/input/select.html index 879a537a..026d48e3 100644 --- a/spec/assets/input/select.html +++ b/spec/assets/input/select.html @@ -5,6 +5,7 @@