I have a form and I want to know if any of the input fields in the form are focused or not?
I read the 'NgForm' documentation but didn't find anything related to 'focus'.
I found touched but it doesn't satisfy needs.
hasFocus() : whether the document or any element inside the document has focus. document. activeElement : Property containing which element currently has focus.
HTML DOM Document hasFocus() The hasFocus() method returns a true if the document (or any element in the document) has focus. Otherwise it returns false .
The ng-focus directive tells AngularJS what to do when an HTML element gets focus. The ng-focus directive from AngularJS will not override the element's original onfocus event, both will be executed.
The HTMLElement. focus() method sets focus on the specified element, if it can be focused. The focused element is the element that will receive keyboard and similar events by default.
You can use the focus and blur events, to track as fields gain or lose focus :
<input (focus)="onFocus()" (blur)="onBlur()">
There are also javascript’s own :
document.hasFocus() : whether the document or any element inside the document has focus.
document.activeElement : Property containing which element currently has focus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With