I would like to focus an input when a variable has a certain value.
I thought I could do this with a dynamic attribute, but it seems that inputs do not have focus as a dynamic attribute…
My next thought to work around this would be to dynamically select and focus the inputs when the update event happens on the variable, for example:
var registrationStep = 1;
<input type=‘text’ id=‘input1’>
<input type=‘text’ id=‘input2’>
registrationStep.onChange = function(registrationStep) {
$(’#input+“registrationStep” ').focus();
}
I would like to be able to do this within wappler, is there a way?
or maybe I am approaching it from the wrong direction and there is another way to do this?
On second thoughts, I don’t think this will do what you want.
You could create a second variable: "myform.input" + var1.value + ".focus()"
… and then apply this onclick event to the button: dmx-on:click="var2.value"
But I have many inputs that I want it to iterate through…
I can do with javascript like I showed above, I’m just wondering if there is a way within Wappler that I don’t know about
I may not have understood quite what you need, but using the example in the second reply I gave, you can have any number of inputs - the variable registrationStep could be given any value, corresponding to whatever inputs you have.
Here is a simple example. You should be able to paste this into a new, empty page in Wappler and hopefully see what I mean. I’ve added a select which will set the first variable to a number. Clicking the button will then apply focus according to the selection made. You could have a thousand fields and no extra code would be required (except adding numbers to the select control, as used in this example).
Whoa this is really cool, I did not know you could set the value of a variable to a function, then set the action of a button or any event simply state the variable, which calls the function…
Thanks so much for teaching me this, super useful!!