_hyperscript
_hyperscript copied to clipboard
Feature Request: `clear` command
Resetting an element or clearing its contents are pretty common behaviors. Right now, to clear an element you do put '' into #ref
or set #ref's innerHTML to ''
. Clearing an input requires set #input's value to ''
. Resetting a form requires call #form.reset()
.
A clear
command that handles the first two cases would be pretty nice to have. The last case with the form though may not warrant and entire new command, as it's fairly straightforward and clear.
Does clear <select />
unset the value, or remove all the <option>
s?
Good question. I'll tentatively suggest that it should clear the value of the select, so unset the value.
Alternatively, we do two different commands - clear
always deletes the innerHTML, and reset
always unsets the value where applicable.
Yes, I'd vote that we only reset the value of a select box, and not touch the options. In modern HTML, input boxes can also have option lists, and we shouldn't make different behaviors for each element type.
This goes double because of hyperscript's purpose as a glue language for dynamic behaviors (clearing an input's value), and NOT as a way to dynamically generate DOM elements (removing its options).