Autofocus next text field

0
Hello, I am trying to set autofocus to the input fields for phone number [TEXT BOX 1] - [TEXT BOX 2] - [TEXT BOX 3], each masked for 3-3-4 digits respectively. I am using jquery function: setTimeout(function() { $('input').keyup(function(){ if($(this).val().length==$(this).attr("maxlength")){ var i = $('input').index(this); $('input').eq(i+1).focus(); } }); },500); This code tabs off on the very first number entered in the box or even if I backspace the content. I'm not sure if mendix is counting underscores (displayed when masked as digits) as input. Please, let me know what is wrong here.
asked
1 answers
0

Mendix is indeed counting underscores unless the input is still empty. So you have several options. You could use isNaN() on the value to check if it still contains non-numeric values and only focus next when false. Or you could remove the input mask and validate otherwise. You could prevent users entering anything else than numbers like here. Another example of implementing what you're doing here.  They also account for using backspace to go back and for focussing only inputs inside a container with a given class. Otherwise you would focus the next input on the page when the third textbox is filled, which may not be what you want.

answered