_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

Feature Request: `clear` command

Open ajusa opened this issue 2 years ago • 5 comments

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.

ajusa avatar Dec 19 '21 15:12 ajusa

Does clear <select /> unset the value, or remove all the <option>s?

dz4k avatar Dec 19 '21 16:12 dz4k

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.

ajusa avatar Dec 19 '21 16:12 ajusa

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).

benpate avatar Dec 19 '21 21:12 benpate