GUACAMOLE-302: Allow guacForm and guacFormField directives to specify which field needs to be focused.

This commit is contained in:
m-khan-glyptodon
2019-06-07 13:38:27 -07:00
parent 52d2fe1661
commit 19f0de4ebc
5 changed files with 28 additions and 10 deletions

View File

@@ -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.

View File

@@ -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',

View File

@@ -10,7 +10,9 @@
<guac-form-field ng-repeat="field in form.fields" namespace="namespace"
ng-if="isVisible(field)"
data-disabled="disabled"
field="field" model="values[field.name]"></guac-form-field>
focused="isFocused(field)"
field="field"
model="values[field.name]"></guac-form-field>
</div>
</div>

View File

@@ -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];

View File

@@ -27,6 +27,7 @@
namespace="'LOGIN'"
content="remainingFields"
model="enteredValues"
focused="relevantField.name"
data-disabled="submitted"></guac-form>
</div>