From 494ba11675de903af9c9b5b8a8332a67a7b007fd Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Mon, 23 Sep 2019 15:29:13 +0300 Subject: [PATCH] feature(theme-shared): import ngx-validate --- .../change-password/change-password.component.html | 11 +++++------ .../change-password/change-password.component.ts | 12 ++++++++++-- .../theme-shared/src/lib/theme-shared.module.ts | 3 ++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/change-password/change-password.component.html b/npm/ng-packs/packages/theme-shared/src/lib/components/change-password/change-password.component.html index f483f23e94..75f71556eb 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/change-password/change-password.component.html +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/change-password/change-password.component.html @@ -3,7 +3,7 @@

{{ 'AbpIdentity::ChangePassword' | abpLocalization }}

-
+
* {{ 'AbpIdentity::DisplayName:NewPassword' | abpLocalization }} *
-
+
* -
- {{ 'AbpIdentity::Identity.PasswordConfirmationFailed' | abpLocalization }} -
@@ -27,6 +24,8 @@ - {{ 'AbpIdentity::Save' | abpLocalization }} + {{ + 'AbpIdentity::Save' | abpLocalization + }} diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/change-password/change-password.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/change-password/change-password.component.ts index 00d285b3c5..1f7dcab4af 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/change-password/change-password.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/change-password/change-password.component.ts @@ -11,7 +11,7 @@ import { ViewChild, } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; -import { comparePasswords } from '@ngx-validate/core'; +import { comparePasswords, Validation } from '@ngx-validate/core'; import { Store } from '@ngxs/store'; import snq from 'snq'; import { finalize } from 'rxjs/operators'; @@ -19,6 +19,8 @@ import { ToasterService } from '../../services/toaster.service'; const { minLength, required } = Validators; +const PASSWORD_FIELDS = ['newPassword', 'repeatNewPassword']; + @Component({ selector: 'abp-change-password', templateUrl: './change-password.component.html', @@ -46,6 +48,12 @@ export class ChangePasswordComponent implements OnInit, OnChanges { modalBusy: boolean = false; + mapErrorsFn: Validation.MapErrorsFn = function(errors, groupErrors, control) { + if (PASSWORD_FIELDS.indexOf(control.name) < 0) return errors; + + return errors.concat(groupErrors.filter(({ key }) => key === 'passwordMismatch')); + }; + constructor(private fb: FormBuilder, private store: Store, private toasterService: ToasterService) {} ngOnInit(): void { @@ -56,7 +64,7 @@ export class ChangePasswordComponent implements OnInit, OnChanges { repeatNewPassword: ['', required], }, { - validators: [comparePasswords(['newPassword', 'repeatNewPassword'])], + validators: [comparePasswords(PASSWORD_FIELDS)], }, ); } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts b/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts index 40f09d6c5f..c6dddaa04f 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts @@ -18,6 +18,7 @@ import styles from './contants/styles'; import { ErrorHandler } from './handlers/error.handler'; import { chartJsLoaded$ } from './utils/widget-utils'; import { TableEmptyMessageComponent } from './components/table-empty-message/table-empty-message.component'; +import { NgxValidateCoreModule } from '@ngx-validate/core'; export function appendScript(injector: Injector) { const fn = function() { @@ -40,7 +41,7 @@ export function appendScript(injector: Injector) { } @NgModule({ - imports: [CoreModule, ToastModule], + imports: [CoreModule, ToastModule, NgxValidateCoreModule], declarations: [ BreadcrumbComponent, ButtonComponent,