Javascript noob here. A bit stuck with respect to a mfa input field verification I'm trying to implement for my web app.
Instead of having the user hit the "Submit" button after they enter an mfa code in the input field, I want to simply fire my backend service when the field length reaches 6 characters. I've seen this done elegantly on a number of sites.
In my case it fires the lambdas function 4 times in a row when I click out of the field. I can't quite get my head around why it's firing 4 times, as opposed to once?
My assumption is because I'm trying to account for keyup, keypress, blur, and change simultaneously? By doing so I was trying to factor for multiple user behaviors, for example: loss of field focus, a tab out of the field, or an "enter" key press.
$("#login2fa").inputmask("9 9 9 9 9 9").on("keyup keypress blur change", function() {
var $el = $(this);
var code = $el.val().replace(/[^\d]/g, '');
if (code.length === 6) {
lambdas.userLoginMfaConfirm(session_token, code, handleConfirmResult);
}
});