blob: cb4d830535a150a0e0b2d31609956d547fcbb4ba [file] [log] [blame]
Gunnar Millsb7ea2792018-07-18 13:01:48 -05001window.angular && (function(angular) {
2 'use strict';
3
4 angular.module('app.common.directives')
5 .directive('setFocusOnNewInput', function() {
6 return function(scope, element, attrs) {
7 var elem = window.document.getElementById(element[0].id);
8 // Focus on the newly created input.
9 // Since this directive is also called when initializing fields
10 // on a page load, need to determine if the call is from a page load
11 // or from the user pressing the "Add new" button. The easiest way to
12 // do this is to check if the field is empty, if it is we know this is
13 // a new field since all empty fields are removed from the array.
14 if (!scope[attrs.ngModel] && elem) {
15 elem.focus();
16 }
17 };
18 });
19})(window.angular);