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