From 19f0de4ebcf07deff3048eb44207fe4ca7efa284 Mon Sep 17 00:00:00 2001 From: m-khan-glyptodon Date: Fri, 7 Jun 2019 13:38:27 -0700 Subject: [PATCH] GUACAMOLE-302: Allow guacForm and guacFormField directives to specify which field needs to be focused. --- .../src/main/webapp/app/form/directives/form.js | 13 ++++++++++++- .../main/webapp/app/form/directives/formField.js | 9 ++++++++- .../src/main/webapp/app/form/templates/form.html | 4 +++- .../src/main/webapp/app/login/directives/login.js | 11 ++++------- .../src/main/webapp/app/login/templates/login.html | 1 + 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/guacamole/src/main/webapp/app/form/directives/form.js b/guacamole/src/main/webapp/app/form/directives/form.js index be2f3b176..925128b9e 100644 --- a/guacamole/src/main/webapp/app/form/directives/form.js +++ b/guacamole/src/main/webapp/app/form/directives/form.js @@ -72,7 +72,14 @@ angular.module('form').directive('guacForm', [function form() { * * @type Boolean */ - disabled : '=' + disabled : '=', + + /** + * The name of the field to be focused, if any. + * + * @type String + */ + focused : '=' }, templateUrl: 'app/form/templates/form.html', @@ -180,6 +187,10 @@ angular.module('form').directive('guacForm', [function form() { }); + $scope.isFocused = function isFocused(field) { + return field && (field.name === $scope.focused); + }; + /** * Returns whether the given field should be displayed to the * current user. diff --git a/guacamole/src/main/webapp/app/form/directives/formField.js b/guacamole/src/main/webapp/app/form/directives/formField.js index 15adc29e4..cf3efd027 100644 --- a/guacamole/src/main/webapp/app/form/directives/formField.js +++ b/guacamole/src/main/webapp/app/form/directives/formField.js @@ -61,7 +61,14 @@ angular.module('form').directive('guacFormField', [function formField() { * * @type Boolean */ - disabled : '=' + disabled : '=', + + /** + * Whether this field should be focused. + * + * @type Boolean + */ + focused : '=' }, templateUrl: 'app/form/templates/formField.html', diff --git a/guacamole/src/main/webapp/app/form/templates/form.html b/guacamole/src/main/webapp/app/form/templates/form.html index fe0c8903a..6b19bcce2 100644 --- a/guacamole/src/main/webapp/app/form/templates/form.html +++ b/guacamole/src/main/webapp/app/form/templates/form.html @@ -10,7 +10,9 @@ + focused="isFocused(field)" + field="field" + model="values[field.name]"> diff --git a/guacamole/src/main/webapp/app/login/directives/login.js b/guacamole/src/main/webapp/app/login/directives/login.js index 6fc3441b0..a4145483b 100644 --- a/guacamole/src/main/webapp/app/login/directives/login.js +++ b/guacamole/src/main/webapp/app/login/directives/login.js @@ -151,7 +151,7 @@ angular.module('login').directive('guacLogin', [function guacLogin() { $scope.enteredValues[field.name] = ''; }); - console.log(mostRelevantField()); + $scope.relevantField = getRelevantField(); }); @@ -203,8 +203,6 @@ angular.module('login').directive('guacLogin', [function guacLogin() { delete $scope.enteredValues[field.name]; }); - - console.log(mostRelevantField()); } })); @@ -212,15 +210,14 @@ angular.module('login').directive('guacLogin', [function guacLogin() { }; /** - * Returns the field most relevant field to the user given the current - * state of the login process. This will normally be the first empty - * field. + * Returns the field most relevant to the user given the current state + * of the login process. This will normally be the first empty field. * * @return {Field} * The field most relevant, null if there is no single most relevant * field. */ - var mostRelevantField = function findMostRelevantField() { + var getRelevantField = function getRelevantField() { for (var i = 0; i < $scope.remainingFields.length; i++) { var field = $scope.remainingFields[i]; diff --git a/guacamole/src/main/webapp/app/login/templates/login.html b/guacamole/src/main/webapp/app/login/templates/login.html index 79e6081f0..04111edb4 100644 --- a/guacamole/src/main/webapp/app/login/templates/login.html +++ b/guacamole/src/main/webapp/app/login/templates/login.html @@ -27,6 +27,7 @@ namespace="'LOGIN'" content="remainingFields" model="enteredValues" + focused="relevantField.name" data-disabled="submitted">