Nice, this is the way it was intended to use. We can call "myInput" a generator function, as it generates a new UI element or a group of elements.
Just, inputText already implemented this functionality, so this gives the same result:
<script>functionmyInput(s,width){letret=inputText(s,{baseAttrib:"margin: 3px; ",fieldWidth:[100,100],});returnret;// Return reference for access}h1("Input-Test");myInput("Short");myInput("VeryLong");letrmedium=myInput("Medium");rmedium.oninput=(e)=>console.log(e.target.value)</script>
(It seems the documentation is outdated and needs some urgfent update...)
Interestingly, it is possible put also some callback functions inside the "generator" function, so you can also implement some general behavoir. In the following example, a key filter was implemented inside the myInput:
<script>"use strict";// Make the input elements / key filterfunctionmyInput(txt,rule){// Create text and input fieldidiv(txt,"width: 100px;")letinp=make("input",{value:1})br()// Key filterinp.onkeydown=(e)=>{if(e.key.length==1)if(!e.key.match(rule))e.preventDefault()}// Filter keysreturninp}// Build the pageh1("Binary converter")sidiv("",_box+_bigPadding)letb=myInput("binary","[0,1]")letd=myInput("decimal","[0-9]")b.oninput=()=>d.value=parseInt(b.value,2)d.oninput=()=>b.value=(parseInt(d.value,10)>>>0).toString(2);</script>
Nice, this is the way it was intended to use. We can call "myInput" a generator function, as it generates a new UI element or a group of elements.
Just, inputText already implemented this functionality, so this gives the same result:
(It seems the documentation is outdated and needs some urgfent update...)
Interestingly, it is possible put also some callback functions inside the "generator" function, so you can also implement some general behavoir. In the following example, a key filter was implemented inside the myInput:
(see examples->Binary)
Thank you Eckehard :-)
Just updated this part of the documentation...