Use the custom validation

This commit is contained in:
mauriziovitale84
2016-09-06 14:35:15 +01:00
parent 07e142bd53
commit 9725fb30f9
2 changed files with 16 additions and 2 deletions

View File

@@ -12,4 +12,6 @@
</label> </label>
</p> </p>
</div> </div>
<alfresco-login [providers]="providers" (onSuccess)="onLogin($event)" (onError)="onError($event)"></alfresco-login> <alfresco-login (executeOutcome)="validateForm($event)" [providers]="providers"
(onSuccess)="onLogin($event)"
(onError)="onError($event)" #alfrescologin></alfresco-login>

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import {Component} from '@angular/core'; import {Component, ViewChild} from '@angular/core';
import {AlfrescoLoginComponent} from 'ng2-alfresco-login'; import {AlfrescoLoginComponent} from 'ng2-alfresco-login';
import {ROUTER_DIRECTIVES, Router} from '@angular/router'; import {ROUTER_DIRECTIVES, Router} from '@angular/router';
@@ -30,6 +30,9 @@ declare let __moduleName: string;
}) })
export class LoginDemoComponent { export class LoginDemoComponent {
@ViewChild('alfrescologin')
alfrescologin: any;
providers: string = 'ECM'; providers: string = 'ECM';
constructor(public router: Router) { constructor(public router: Router) {
@@ -67,4 +70,13 @@ export class LoginDemoComponent {
this.providers = undefined; this.providers = undefined;
} }
} }
validateForm(event: any) {
let values = event.values;
if (values.controls['username'].value === 'invalidUsername') {
this.alfrescologin.addCustomError('username', 'the username is in blacklist');
event.preventDefault();
}
}
} }