Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api] Introduce Page.select method (#779)
This patch adds `Page.select` method to select values in a `select` tag.
- Loading branch information
1 parent
acdb588
commit 45f2640
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Selection Test</title> | ||
</head> | ||
<body> | ||
<select> | ||
<option value="black">Black</option> | ||
<option value="blue">Blue</option> | ||
<option value="brown">Brown</option> | ||
<option value="cyan">Cyan</option> | ||
<option value="gray">Gray</option> | ||
<option value="green">Green</option> | ||
<option value="indigo">Indigo</option> | ||
<option value="magenta">Magenta</option> | ||
<option value="orange">Orange</option> | ||
<option value="pink">Pink</option> | ||
<option value="purple">Purple</option> | ||
<option value="red">Red</option> | ||
<option value="violet">Violet</option> | ||
<option value="white">White</option> | ||
<option value="yellow">Yellow</option> | ||
</select> | ||
<script> | ||
window.result = { | ||
onInput: null, | ||
onChange: null, | ||
}; | ||
|
||
let select = document.querySelector('select'); | ||
|
||
function makeEmpty() { | ||
for (let i = select.options.length - 1; i >= 0; --i) { | ||
select.remove(i); | ||
} | ||
} | ||
|
||
function makeMultiple() { | ||
select.setAttribute('multiple', true); | ||
} | ||
|
||
select.addEventListener('input', () => { | ||
result.onInput = Array.from(select.querySelectorAll('option:checked')).map((option) => { | ||
return option.value; | ||
}); | ||
}, false); | ||
|
||
select.addEventListener('change', () => { | ||
result.onChange = Array.from(select.querySelectorAll('option:checked')).map((option) => { | ||
return option.value; | ||
}); | ||
}, false); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters