diff --git a/packages/core/src/lib/abstracts/abstract-validation.directive.ts b/packages/core/src/lib/abstracts/abstract-validation.directive.ts index e7a5cb5..e3637b7 100644 --- a/packages/core/src/lib/abstracts/abstract-validation.directive.ts +++ b/packages/core/src/lib/abstracts/abstract-validation.directive.ts @@ -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, @@ -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); } diff --git a/packages/core/src/lib/core.module.ts b/packages/core/src/lib/core.module.ts index f058909..255edfe 100644 --- a/packages/core/src/lib/core.module.ts +++ b/packages/core/src/lib/core.module.ts @@ -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], @@ -66,6 +67,10 @@ export class NgxValidateCoreModule { provide: VALIDATION_VALIDATE_ON_SUBMIT, useValue: config.validateOnSubmit, }, + { + provide: SKIP_VALIDATION, + useValue: config.skipValidation || false, + }, ], }; } diff --git a/packages/core/src/lib/tokens/index.ts b/packages/core/src/lib/tokens/index.ts index c0375a9..1f01302 100644 --- a/packages/core/src/lib/tokens/index.ts +++ b/packages/core/src/lib/tokens/index.ts @@ -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'; diff --git a/packages/core/src/lib/tokens/skip-validation.token.ts b/packages/core/src/lib/tokens/skip-validation.token.ts new file mode 100644 index 0000000..18dee54 --- /dev/null +++ b/packages/core/src/lib/tokens/skip-validation.token.ts @@ -0,0 +1,3 @@ +import { InjectionToken } from '@angular/core'; + +export const SKIP_VALIDATION = new InjectionToken('validation.skip.validation');