diff options
Diffstat (limited to 'ka.js')
| -rw-r--r-- | ka.js | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -1,5 +1,6 @@ (()=>{ doc = document; + entries = Object.entries; var ep = Element.prototype; ep.attr = function(name){ @@ -10,7 +11,7 @@ return this; }; ep.$attrs = function(attrs) { - Object.entries(attrs).forEach(([attr, value]) => this.$attr(attr, value)); + entries(attrs).forEach(([attr, value]) => this.$attr(attr, value)); return this; } ep.$cls = function(cls) { @@ -26,14 +27,19 @@ } const getvalue = x => x.value; ep.$change2state = function(state, field, valgetter=getvalue) { - this.onchange = () => { - state[field] = valgetter(this); + this.oninput = () => { + this.setCustomValidity(''); + if (this.validity.valid) { + state[field] = valgetter(this); + } else { + this.reportValidity(); + } }; return this; } tag = (name, attrs, ...children) => { const el = doc.createElement(name); - el.$attrs(attrs||{}); + attrs && el.$attrs(attrs); for (const child of children.filter(x=>x)) { el.appendChild((typeof(child) === 'string') ? doc.createTextNode(child) : child); } @@ -43,7 +49,7 @@ labelfor = (for_, ...children) => tag("label", {"for":for_}, ...children); img = (src) => tag("img", {src}); input = (type) => tag("input", {type}); - const TRIVIAL = "main,section,nav,h1,h2,h3,p,,div,span,select,table,tr,td"; + const TRIVIAL = "main,section,nav,h1,h2,h3,p,b,div,span,form,select,button,table,tr,td"; for (let name of TRIVIAL.split(",")) { window[name] = (...children) => tag(name, null, ...children); } |
