From ec8c9448a737624199799c190e5c0fa9f746666e Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Wed, 7 Sep 2016 16:15:09 +0100 Subject: [PATCH] Add custom validation rules docs --- ng2-components/ng2-alfresco-login/README.md | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ng2-components/ng2-alfresco-login/README.md b/ng2-components/ng2-alfresco-login/README.md index 6ca7fb2dc3..d93e325e1a 100644 --- a/ng2-components/ng2-alfresco-login/README.md +++ b/ng2-components/ng2-alfresco-login/README.md @@ -177,6 +177,36 @@ Alternatively you can bind to your component properties and provide values dynam ``` +#### Customize Validation rules +If needed it is possible customize the validation rules of the login +form. You can add/modify the default rules of the login form. + +**MyCustomLogin.component.html** +```html + +``` + +**MyCustomLogin.component.ts** +```ts + +export class MyCustomLogin { + customValidation: any; + + constructor(public router: Router) { + this.customValidation = { + username: ['', Validators.compose([Validators.required, Validators.minLength(8), Validators.maxLength(10)])], + password: ['', Validators.required] + }; + } + + ngOnInit() { + this.alfrescologin.addCustomValidationError('username', 'minlength', 'Username must be at least 8 characters.'); + this.alfrescologin.addCustomValidationError('username', 'maxlength', 'Username must not be longer than 11 characters.'); + } +} +``` + #### Controlling form submit execution behaviour If absolutely needed it is possible taking full control over form