mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Fix dynamic value inside the min length error message (#1523)
This commit is contained in:
committed by
Mario Romano
parent
e846a15aa8
commit
89bcdbef24
@@ -37,19 +37,20 @@ export class LoginDemoComponent implements OnInit {
|
|||||||
disableCsrf: boolean = false;
|
disableCsrf: boolean = false;
|
||||||
isECM: boolean = true;
|
isECM: boolean = true;
|
||||||
isBPM: boolean = false;
|
isBPM: boolean = false;
|
||||||
|
customMinLenght: number = 2;
|
||||||
|
|
||||||
constructor(private router: Router,
|
constructor(private router: Router,
|
||||||
private storage: StorageService,
|
private storage: StorageService,
|
||||||
private logService: LogService) {
|
private logService: LogService) {
|
||||||
this.customValidation = {
|
this.customValidation = {
|
||||||
username: ['', Validators.compose([Validators.required, Validators.minLength(2)])],
|
username: ['', Validators.compose([Validators.required, Validators.minLength(this.customMinLenght)])],
|
||||||
password: ['', Validators.required]
|
password: ['', Validators.required]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.alfrescologin.addCustomValidationError('username', 'required', 'LOGIN.MESSAGES.USERNAME-REQUIRED');
|
this.alfrescologin.addCustomValidationError('username', 'required', 'LOGIN.MESSAGES.USERNAME-REQUIRED');
|
||||||
this.alfrescologin.addCustomValidationError('username', 'minlength', 'LOGIN.MESSAGES.USERNAME-MIN');
|
this.alfrescologin.addCustomValidationError('username', 'minlength', 'LOGIN.MESSAGES.USERNAME-MIN', {customMinLenght: this.customMinLenght});
|
||||||
this.alfrescologin.addCustomValidationError('password', 'required', 'LOGIN.MESSAGES.PASSWORD-REQUIRED');
|
this.alfrescologin.addCustomValidationError('password', 'required', 'LOGIN.MESSAGES.PASSWORD-REQUIRED');
|
||||||
|
|
||||||
if (this.storage.hasItem('providers')) {
|
if (this.storage.hasItem('providers')) {
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"MESSAGES": {
|
"MESSAGES": {
|
||||||
"USERNAME-REQUIRED": "Required",
|
"USERNAME-REQUIRED": "Required",
|
||||||
"USERNAME-MIN": "Your username needs to be at least 4 characters.",
|
"USERNAME-MIN": "Your username needs to be at least {{customMinLenght}} characters.",
|
||||||
"PASSWORD-REQUIRED": "Enter your password to sign in",
|
"PASSWORD-REQUIRED": "Enter your password to sign in",
|
||||||
"LOGIN-ERROR-CREDENTIALS": "You have entered an invalid username or password",
|
"LOGIN-ERROR-CREDENTIALS": "You have entered an invalid username or password",
|
||||||
"LOGIN-ERROR-PROVIDERS": "Providers cannot be undefined",
|
"LOGIN-ERROR-PROVIDERS": "Providers cannot be undefined",
|
||||||
|
@@ -65,6 +65,8 @@ export class AlfrescoLoginComponent implements OnInit {
|
|||||||
|
|
||||||
formError: { [id: string]: string };
|
formError: { [id: string]: string };
|
||||||
|
|
||||||
|
minLenght: number = 2;
|
||||||
|
|
||||||
private _message: { [id: string]: { [id: string]: string } };
|
private _message: { [id: string]: { [id: string]: string } };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -220,8 +222,14 @@ export class AlfrescoLoginComponent implements OnInit {
|
|||||||
* @param ruleId - i.e. required | minlength | maxlength
|
* @param ruleId - i.e. required | minlength | maxlength
|
||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
public addCustomValidationError(field: string, ruleId: string, msg: string) {
|
public addCustomValidationError(field: string, ruleId: string, msg: string, params?: any) {
|
||||||
this._message[field][ruleId] = msg;
|
if (params) {
|
||||||
|
this.translateService.get(msg, params).subscribe((res: string) => {
|
||||||
|
this._message[field][ruleId] = res;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this._message[field][ruleId] = msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -274,18 +282,21 @@ export class AlfrescoLoginComponent implements OnInit {
|
|||||||
private initFormFieldsMessagesDefault() {
|
private initFormFieldsMessagesDefault() {
|
||||||
this._message = {
|
this._message = {
|
||||||
'username': {
|
'username': {
|
||||||
'required': 'LOGIN.MESSAGES.USERNAME-REQUIRED',
|
'required': 'LOGIN.MESSAGES.USERNAME-REQUIRED'
|
||||||
'minlength': 'LOGIN.MESSAGES.USERNAME-MIN'
|
|
||||||
},
|
},
|
||||||
'password': {
|
'password': {
|
||||||
'required': 'LOGIN.MESSAGES.PASSWORD-REQUIRED'
|
'required': 'LOGIN.MESSAGES.PASSWORD-REQUIRED'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.translateService.get('LOGIN.MESSAGES.USERNAME-MIN', {minLenght: this.minLenght}).subscribe((res: string) => {
|
||||||
|
this._message['username']['minlength'] = res;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private initFormFieldsDefault() {
|
private initFormFieldsDefault() {
|
||||||
this.form = this._fb.group({
|
this.form = this._fb.group({
|
||||||
username: ['', Validators.compose([Validators.required, Validators.minLength(2)])],
|
username: ['', Validators.compose([Validators.required, Validators.minLength(this.minLenght)])],
|
||||||
password: ['', Validators.required]
|
password: ['', Validators.required]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"MESSAGES": {
|
"MESSAGES": {
|
||||||
"USERNAME-REQUIRED": "Required",
|
"USERNAME-REQUIRED": "Required",
|
||||||
"USERNAME-MIN": "Your username needs to be at least 4 characters.",
|
"USERNAME-MIN": "Your username needs to be at least {{minLenght}} characters.",
|
||||||
"PASSWORD-REQUIRED": "Enter your password to sign in",
|
"PASSWORD-REQUIRED": "Enter your password to sign in",
|
||||||
"LOGIN-ERROR-CREDENTIALS": "You have entered an invalid username or password",
|
"LOGIN-ERROR-CREDENTIALS": "You have entered an invalid username or password",
|
||||||
"LOGIN-ERROR-PROVIDERS": "Providers cannot be undefined",
|
"LOGIN-ERROR-PROVIDERS": "Providers cannot be undefined",
|
||||||
|
Reference in New Issue
Block a user