summaryrefslogtreecommitdiffstats
path: root/app/common/directives/input.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/common/directives/input.js')
-rw-r--r--app/common/directives/input.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/common/directives/input.js b/app/common/directives/input.js
new file mode 100644
index 0000000..cb4d830
--- /dev/null
+++ b/app/common/directives/input.js
@@ -0,0 +1,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);
OpenPOWER on IntegriCloud