My goal is to create a form where, upon leaving field one (blur), the system will check if the data inputted is the word "test". If the data does not contain this word, I want the focus to return to field 1.
<form name='yourForm' novalidate ng-submit="save(yourForm)">
<label>Field 1</label>
<input type="email" name="first" ng-model="fname" ng-blur="displayData(fname)">
<br><br>
<label>Field 2</label>
<input type="text" name="last" ng-model="lname" ng-blur="displayData(lname)">
<button type="button">finish</button>
</form>
I am currently having difficulty figuring out how to set the field focus using the field's name, id, or ng-model in Angular.
The desired functionality I would like to achieve is something similar to the following JavaScript code:
var inp = document.getElementsByTagName('INPUT')[1];
inp.focus();
However, I am unsure of how to determine the index or retrieve the name of the input for implementation.