Skip to content

Commit 4281f61

Browse files
committed
JBDS-4066 Improve error reporting on account info page
Fix: - moves validation logic to controller; - adds reset for error reported after submit if any field is edited; - elements location within page, so nothing moves after error appears.
1 parent 8018f6a commit 4281f61

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

browser/pages/account/account.html

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,37 @@
1111
<form name="accountForm" id="accountForm" class="form-horizontal" ng-submit="acctCtrl.login()">
1212
<div class="login-form-input-container form-group has-feedback" ng-class="{'has-error has-feedback': (accountForm.$submitted || accountForm.username.$touched) && accountForm.username.$invalid}">
1313
<label for="username" class="login-form-label">Username</label>
14-
<input type="text" id="username" name="username" class="login-form-input form-control" ng-model="acctCtrl.username" ng-disabled="acctCtrl.isLoginBtnClicked" required aria-describedby="usernameStatus" autofocus/>
15-
<!--<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true" ng-show="(accountForm.$submitted || accountForm.username.$touched) && accountForm.username.$invalid"></span>-->
14+
<input type="text" id="username" name="username" class="login-form-input form-control" ng-change="acctCtrl.resetLoginErrors()" ng-model="acctCtrl.username" ng-disabled="acctCtrl.isLoginBtnClicked" required aria-describedby="usernameStatus" autofocus/>
1615
<span id="usernameStatus" class="sr-only" ng-show="(accountForm.$submitted || accountForm.username.$touched) && accountForm.username.$invalid">(error)</span>
1716
</div>
1817
<div class="login-form-input-container form-group has-feedback" ng-class="{'has-error has-feedback': (accountForm.$submitted || accountForm.password.$touched) && accountForm.password.$invalid}">
1918
<label for="password" class="login-form-label">Password</label>
20-
<input type="password" id="password" name="password" class="login-form-input form-control" ng-model="acctCtrl.password" ng-disabled="acctCtrl.isLoginBtnClicked" required aria-describedby="passwordStatus"/>
21-
<!--<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true" ng-show="(accountForm.$submitted || accountForm.password.$touched) && accountForm.password.$invalid"></span>-->
19+
<input type="password" id="password" name="password" class="login-form-input form-control" ng-change="acctCtrl.resetLoginErrors()" ng-model="acctCtrl.password" ng-disabled="acctCtrl.isLoginBtnClicked" required aria-describedby="passwordStatus"/>
2220
<span id="passwordStatus" class="sr-only" ng-show="(accountForm.$submitted || accountForm.password.$touched) && accountForm.password.$invalid">(error)</span>
2321
</div>
24-
<div ng-show="(accountForm.$submitted || accountForm.password.$touched) && ((acctCtrl.authFailed || acctCtrl.tandcNotSigned || acctCtrl.httpError) || (accountForm.username.$error.required || accountForm.password.$error.required))" class="form-group has-error pull-right">
25-
<div id="invalidLoginError" ng-show="accountForm.$submitted && acctCtrl.authFailed && !accountForm.username.$error.required && !accountForm.password.$error.required" class="help-block">
22+
<div class="form-group has-error" style="height: 160px;">
23+
<div id="invalidLoginError" ng-show="acctCtrl.authFailed && !accountForm.username.$error.required && !accountForm.password.$error.required" class="help-block form-group has-error">
2624
<span id="invalidLoginIcon" class="pficon pficon-error-circle-o"></span>
2725
<strong id="invalidLoginMessage">Invalid account information, please try again.</strong>
2826
</div>
29-
<div ng-show="(accountForm.$submitted || accountForm.password.$touched) && accountForm.username.$error.required && accountForm.password.$error.required" class="help-block">
30-
<span class="pficon pficon-error-circle-o"></span>
31-
<strong>Please enter your username and password.</strong>
32-
</div>
33-
<div ng-show="accountForm.username.$error.required === !accountForm.password.$error.required" class="help-block">
27+
<div ng-show="acctCtrl.isInvalid(accountForm.username) && acctCtrl.isValid(accountForm.password)" class="help-block form-group has-error">
3428
<span class="pficon pficon-error-circle-o"></span>
3529
<strong>Please enter your username.</strong>
3630
</div>
37-
<div ng-show="accountForm.password.$error.required === !accountForm.username.$error.required" class="help-block">
31+
<div ng-show="acctCtrl.isInvalid(accountForm.password) && acctCtrl.isValid(accountForm.username)" class="help-block form-group has-error">
3832
<span class="pficon pficon-error-circle-o"></span>
3933
<strong>Please enter your password.</strong>
4034
</div>
41-
<div id="tcError" ng-show="accountForm.$submitted && acctCtrl.tandcNotSigned" class="help-block">
35+
<div ng-show="acctCtrl.isInvalid(accountForm.username) && acctCtrl.isInvalid(accountForm.password)" class="help-block form-group has-error">
36+
<span class="pficon pficon-error-circle-o"></span>
37+
<strong>Please enter your username and password.</strong>
38+
</div>
39+
<div id="tcError" ng-show="acctCtrl.tandcNotSigned" class="help-block form-group has-error">
4240
<span id="tcIcon" class="pficon pficon-error-circle-o"></span>
4341
<strong id="tcMessage">Terms and Conditions for CDK have not been signed.</strong>
4442
</div>
45-
<div id="httpError" ng-show="accountForm.$submitted && acctCtrl.httpError" class="help-block">
46-
<span id="invalidLoginIcon" class="pficon pficon-error-circle-o"></span>
43+
<div id="httpError" ng-show="acctCtrl.httpError" class="help-block form-group has-error">
44+
<span id="NetworkErrorIcon" class="pficon pficon-error-circle-o"></span>
4745
<strong id="httpErrorMessage">Cannot access developers.redhat.com, please check your internet connection.</strong>
4846
</div>
4947
</div>

browser/pages/account/controller.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ class AccountController {
2525
}
2626

2727
login() {
28-
this.authFailed = false;
29-
this.tandcNotSigned = false;
30-
28+
this.resetLoginErrors();
3129
let req = {
3230
method: 'GET',
3331
url: 'https://developers.redhat.com/download-manager/rest/tc-accepted?downloadURL=/file/cdk-2.1.0.zip',
@@ -49,6 +47,20 @@ class AccountController {
4947
.catch(this.handleHttpFailure.bind(this));
5048
}
5149

50+
resetLoginErrors() {
51+
this.authFailed = false;
52+
this.httpError = undefined;
53+
this.tandcNotSigned = false;
54+
}
55+
56+
isInvalid(field) {
57+
return field.$invalid && (field.$dirty || field.$touched);
58+
}
59+
60+
isValid(field) {
61+
return !this.isInvalid(field);
62+
}
63+
5264
getUserAgent() {
5365
return remote.getCurrentWindow().webContents.session.getUserAgent();
5466
}

0 commit comments

Comments
 (0)