Skip to content

Commit

Permalink
add token for SkipValidation config
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmut-gundogdu committed Jan 29, 2024
1 parent 3737a86 commit 211e005
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BLUEPRINTS } from '../constants';
import { ValidationGroupDirective } from '../directives/validation-group.directive';
import { Validation } from '../models';
import {
SKIP_VALIDATION,
VALIDATION_BLUEPRINTS,
VALIDATION_ERROR_TEMPLATE,
VALIDATION_INVALID_CLASSES,
Expand Down Expand Up @@ -113,6 +114,7 @@ export class AbstractValidationDirective implements OnDestroy {
mapErrorsFn: injector.get(VALIDATION_MAP_ERRORS_FN),
targetSelector: injector.get(VALIDATION_TARGET_SELECTOR),
validateOnSubmit: injector.get(VALIDATION_VALIDATE_ON_SUBMIT),
skipValidation: injector.get(SKIP_VALIDATION),
};
this.elRef = injector.get(ElementRef);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/lib/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { VALIDATION_MAP_ERRORS_FN } from './tokens/map-errors-fn.token';
import { VALIDATION_TARGET_SELECTOR } from './tokens/target-selector.token';
import { VALIDATION_VALIDATE_ON_SUBMIT } from './tokens/validate-on-submit.token';
import { defaultMapErrorsFn } from './utils/mappers';
import { SKIP_VALIDATION } from './tokens';

@NgModule({
imports: [CommonModule, FormsModule, ReactiveFormsModule],
Expand Down Expand Up @@ -66,6 +67,10 @@ export class NgxValidateCoreModule {
provide: VALIDATION_VALIDATE_ON_SUBMIT,
useValue: config.validateOnSubmit,
},
{
provide: SKIP_VALIDATION,
useValue: config.skipValidation || false,
},
],
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './invalid-classes.token';
export * from './map-errors-fn.token';
export * from './target-selector.token';
export * from './validate-on-submit.token';
export * from './skip-validation.token';
3 changes: 3 additions & 0 deletions packages/core/src/lib/tokens/skip-validation.token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { InjectionToken } from '@angular/core';

export const SKIP_VALIDATION = new InjectionToken<boolean>('validation.skip.validation');

0 comments on commit 211e005

Please sign in to comment.