Skip to content
This repository was archived by the owner on Jan 5, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
Input,
QueryList,
OnInit,
AfterContentInit
AfterContentInit,
Inject
} from "@angular/core";
import { FormControlName } from "@angular/forms";
import { ErrorMessageService } from "../../Services/error-message.service";
import { MessagesComponent } from "../messages/messages.component";
import { ErrorMessage } from "../../Models/error-message";
import { DISABLE_SUCCESS_STATE } from "../../Tokens/tokens";

@Component({
// tslint:disable:component-selector
Expand Down Expand Up @@ -45,7 +47,8 @@ export class FormGroupComponent implements OnInit, AfterContentInit {
return (
!this.FormControlNames.some(c => !c.valid) &&
this.FormControlNames.some(c => c.dirty && c.touched) &&
!this.validationDisabled
!this.validationDisabled &&
!this.disableSuccessState
);
}

Expand All @@ -58,7 +61,8 @@ export class FormGroupComponent implements OnInit, AfterContentInit {

constructor(
private elRef: ElementRef,
private errorMessageService: ErrorMessageService
private errorMessageService: ErrorMessageService,
@Inject(DISABLE_SUCCESS_STATE) private disableSuccessState: boolean
) {}

ngAfterContentInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { BOOTSTRAP_VERSION } from "../../Tokens/tokens";
@Component({
selector: "bfv-messages",
template: `
<span [ngClass]="className" *ngFor="let message of messages()">{{message}}</span>
<span [ngClass]="className" *ngFor="let message of messages()">{{
message
}}</span>
`,
styles: [
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@angular/core";
import { ControlContainer, FormControl } from "@angular/forms";
import { BootstrapVersion } from "../Enums/BootstrapVersion";
import { BOOTSTRAP_VERSION } from "../Tokens/tokens";
import { DISABLE_SUCCESS_STATE, BOOTSTRAP_VERSION } from "../Tokens/tokens";

export function controlPath(name: string, parent: ControlContainer): string[] {
// tslint:disable-next-line:no-non-null-assertion
Expand All @@ -34,7 +34,8 @@ export class FormControlDirective {
return (
this.bootstrapFour &&
this.control.valid &&
(this.control.touched || this.control.dirty)
(this.control.touched || this.control.dirty) &&
!this.disableSuccessState
);
}

Expand Down Expand Up @@ -74,6 +75,7 @@ export class FormControlDirective {
@Host()
@SkipSelf()
private parent: ControlContainer,
@Inject(DISABLE_SUCCESS_STATE) private disableSuccessState: boolean,
@Inject(BOOTSTRAP_VERSION) private bootstrapVersion: BootstrapVersion
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BootstrapVersion } from "../Enums/BootstrapVersion";
import { ErrorMessage } from "./error-message";

export interface NgBootstrapFormValidationModuleOptions {
disableSuccessState?: boolean;
customErrorMessages?: ErrorMessage[];
bootstrapVersion: BootstrapVersion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { InjectionToken } from "@angular/core";
import { BootstrapVersion } from "../Enums/BootstrapVersion";
import { ErrorMessage } from "../Models/error-message";

export const DISABLE_SUCCESS_STATE = new InjectionToken<ErrorMessage[]>(
"ng-bootstrap-form-validation disable success state"
);

export const CUSTOM_ERROR_MESSAGES = new InjectionToken<ErrorMessage[]>(
"ng-bootstrap-form-validation custom error messages"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { NgModule, ModuleWithProviders } from "@angular/core";
import { FormValidationDirective } from "./Directives/form-validation.directive";
import { MessagesComponent } from "./Components/messages/messages.component";
import { ErrorMessageService } from "./Services/error-message.service";
import { CUSTOM_ERROR_MESSAGES, BOOTSTRAP_VERSION } from "./Tokens/tokens";
import {
DISABLE_SUCCESS_STATE,
CUSTOM_ERROR_MESSAGES,
BOOTSTRAP_VERSION
} from "./Tokens/tokens";
import { BootstrapVersion } from "./Enums/BootstrapVersion";
import { FormGroupComponent } from "./Components/form-group/form-group.component";
import { NgBootstrapFormValidationModuleOptions } from "./Models/NgBootstrapFormValidationModuleOptions";
Expand Down Expand Up @@ -33,6 +37,10 @@ export class NgBootstrapFormValidationModule {
return {
ngModule: NgBootstrapFormValidationModule,
providers: [
{
provide: DISABLE_SUCCESS_STATE,
useValue: userOptions.disableSuccessState || false
},
{
provide: CUSTOM_ERROR_MESSAGES,
useValue: userOptions.customErrorMessages || [],
Expand Down