redom / redom

Tiny (2 KB) turboboosted JavaScript library for creating user interfaces.

Home Page:https://redom.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`value` property for <select> is not handled properly

lacikawiz opened this issue · comments

Using https://redom.js.org/redom.min.js :

The value property when given to a <select> tag won't have the effect of setting the value but simply disappears without any effect.

Look at the following JSFiddle example to demostrate it: https://jsfiddle.net/qsbxr1o4/

const { el, mount } = redom;

const hello = el("select", {size:"3",style:"width:120px",value:"b"}, [
	el("option","a"),
  el("option","b"),
  el("option","c"),
]);

/*---------------------
The `value` parameter is not handled properly. Option "b" should be selected 
but it does not get selected unless the following line is uncommented.
---------------------*/

// hello.value="b"

mount(document.body, hello);

Try:

el("select", {size:"3",style:"width:120px"}, [
  el("option", { value: 'a' },"a"),
  el("option", { value: 'b', selected: true },"b"),
  el("option", { value: 'c' },"c"),
])

https://jsfiddle.net/6utmdzj3/

Shouldn't this work the same way as the <input> where
el("input",{value:"something"}) sets the value at the time of creation?

At least you need to define option values first.. Not sure why that's not enough though, but I personally use selected. RE:DOM calls the DOM without any black magic, so that value sets the property (not attribute).