trim username onBlur #1575 (#1644)

This commit is contained in:
Eugenio Romano 2017-02-21 18:25:17 +00:00 committed by Mario Romano
parent 866c3f91a1
commit 2a257f7b62
3 changed files with 23 additions and 4 deletions

View File

@ -29,6 +29,7 @@
class="center mdl-textfield mdl-js-textfield mdl-textfield--floating-label "> class="center mdl-textfield mdl-js-textfield mdl-textfield--floating-label ">
<label for="username" class="mdl-textfield__label">{{'LOGIN.LABEL.USERNAME' | translate }}</label> <label for="username" class="mdl-textfield__label">{{'LOGIN.LABEL.USERNAME' | translate }}</label>
<input <input
(blur)="trimUsername($event)"
type="text" type="text"
class="mdl-textfield__input" class="mdl-textfield__input"
id="username" id="username"

View File

@ -139,6 +139,16 @@ describe('AlfrescoLogin', () => {
expect(element.querySelector('#password-required').innerText).toEqual('LOGIN.MESSAGES.PASSWORD-REQUIRED'); expect(element.querySelector('#password-required').innerText).toEqual('LOGIN.MESSAGES.PASSWORD-REQUIRED');
}); });
it('should trim the username value', () => {
usernameInput.value = 'username ';
component.form.controls.password.markAsDirty();
usernameInput.dispatchEvent(new Event('blur'));
fixture.detectChanges();
expect(usernameInput.value).toEqual('username');
});
it('should render no validation errors when the username and password are filled', () => { it('should render no validation errors when the username and password are filled', () => {
usernameInput.value = 'fake-username'; usernameInput.value = 'fake-username';
passwordInput.value = 'fake-password'; passwordInput.value = 'fake-password';

View File

@ -26,7 +26,8 @@ declare let componentHandler: any;
selector: 'alfresco-login', selector: 'alfresco-login',
moduleId: module.id, moduleId: module.id,
templateUrl: './alfresco-login.component.html', templateUrl: './alfresco-login.component.html',
styleUrls: ['./alfresco-login.component.css'] styleUrls: ['./alfresco-login.component.css'],
host: {'(blur)': 'onBlur($event)'}
}) })
export class AlfrescoLoginComponent implements OnInit { export class AlfrescoLoginComponent implements OnInit {
@ -130,7 +131,7 @@ export class AlfrescoLoginComponent implements OnInit {
if (args.defaultPrevented) { if (args.defaultPrevented) {
return false; return false;
} else { } else {
this.performeLogin(values); this.performLogin(values);
} }
} }
@ -161,7 +162,7 @@ export class AlfrescoLoginComponent implements OnInit {
* Performe the login service * Performe the login service
* @param values * @param values
*/ */
private performeLogin(values: any) { private performLogin(values: any) {
this.authService.login(values.username, values.password) this.authService.login(values.username, values.password)
.subscribe( .subscribe(
(token: any) => { (token: any) => {
@ -266,6 +267,13 @@ export class AlfrescoLoginComponent implements OnInit {
return !field.valid && field.dirty && !field.pristine; return !field.valid && field.dirty && !field.pristine;
} }
/**
* Trim username
*/
trimUsername(event: any) {
event.target.value = event.target.value.trim();
}
/** /**
* Default formError values * Default formError values
*/ */
@ -299,7 +307,7 @@ export class AlfrescoLoginComponent implements OnInit {
} }
}; };
this.translateService.get('LOGIN.MESSAGES.USERNAME-MIN', {minLength: this.minLength}).subscribe((res: string) => { this.translateService.get('LOGIN.MESSAGES.USERNAME-MIN', {minLength: this.minLength}).subscribe((res: string) => {
this._message['username']['minlength'] = res; this._message['username']['minlength'] = res;
}); });
} }