File

src/lib/components/validation-summary/validation-summary.component.ts

Extends

ControlComponent

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs
Accessors

Constructor

constructor(wmService: WebMapService, refChange: ChangeDetectorRef, render2: Renderer2, elem: ElementRef, webComponents: WebComponentsService, validatorService: BaseValidatorService, bringTopServ1: BringTopService)

Base constructor of the component.

Parameters :
Name Type Optional
wmService WebMapService No
refChange ChangeDetectorRef No
render2 Renderer2 No
elem ElementRef No
webComponents WebComponentsService No
validatorService BaseValidatorService No
bringTopServ1 BringTopService No

Inputs

displayMode
Type : ValidationSummaryDisplayMode

Gets/sets the displayMode property.

headerText
Type : string

Gets/sets the headerText property.

showMessageBox
Type : boolean

Gets/sets the showMessageBox property.

showValidationErrors
Type : boolean

Gets/sets the showValidationErrors property.

validationGroup
Type : string

Gets/sets the validationGroup.

visible
Type : boolean

Gets/sets the visible property.

Methods

formatErrorMessages
formatErrorMessages(separator: string)

join the error messages with the given separator.

Parameters :
Name Type Optional
separator string No
Returns : string

a string with the error messages

ngOnInit
ngOnInit()

angular ngOnInit lifehook. Retrieves the error messages from the validator service.

Returns : void
updateErrorMessages
updateErrorMessages()

Updates the array of error messages.

Returns : void

Properties

Private displayModeInternal
Type : ValidationSummaryDisplayMode
Default value : ValidationSummaryDisplayMode.BulletList

Property with the error message's display mode.

Private errorMessagesInternal
Type : string[]
Default value : []

Property with the errorMessages to be shown.

Private headerTextInternal
Type : string
Default value : ''

Property with the header text.

Private showMessageBoxInternal
Default value : false

Property with the option to create an alert with the error list.

Private showValidationErrorsInternal
Default value : true

Property with the option to show the error messages.

Private validationGroupInternal
Type : string
Default value : ''

Property with validationGroup.

Accessors

headerText
getheaderText()
setheaderText(text: string)

Gets/sets the headerText property.

Parameters :
Name Type Optional
text string No
Returns : void
showValidationErrors
getshowValidationErrors()
setshowValidationErrors(value: boolean)

Gets/sets the showValidationErrors property.

Parameters :
Name Type Optional
value boolean No
Returns : void
displayMode
getdisplayMode()
setdisplayMode(value: ValidationSummaryDisplayMode)

Gets/sets the displayMode property.

Parameters :
Name Type Optional
value ValidationSummaryDisplayMode No
Returns : void
validationSummaryDisplayMode
getvalidationSummaryDisplayMode()

Gets the ValidationSummaryDisplayMode enum.

validationGroup
getvalidationGroup()
setvalidationGroup(value: string)

Gets/sets the validationGroup.

Parameters :
Name Type Optional
value string No
Returns : void
showMessageBox
getshowMessageBox()
setshowMessageBox(value: boolean)

Gets/sets the showMessageBox property.

Parameters :
Name Type Optional
value boolean No
Returns : void
visible
getvisible()
setvisible(value: boolean)

Gets/sets the visible property.

Parameters :
Name Type Optional
value boolean No
Returns : void
errorMessages
geterrorMessages()

Gets the error messages property

hidden
gethidden()

Gets the hidden property Should be hidden if either the visible or the showValidationErrors are set to false.

import { WebMapService } from '@mobilize/angularclient';
import { BringTopService, dataTransfer } from '@mobilize/base-components';
import {
  BaseValidatorService,
  WebComponentsService,
  ControlComponent
} from '@mobilize/winforms-components';
import {
  Component,
  Optional,
  ElementRef,
  Input,
  Renderer2,
  ChangeDetectorRef,
  OnInit
} from '@angular/core';
import { WebFormsBaseValidatorService } from '../../services/base-validator-service/web-forms-base-validator.service';
import { ExceptionHandlerClass, ErrorCodes } from '@mobilize/webmap-core';
import { ValidationSummaryDisplayMode } from '../../contracts/ValidationSummaryDisplayMode';

@Component({
  selector: 'wm-validation-summary',
  templateUrl: './validation-summary.component.html',
  styleUrls: ['./validation-summary.component.scss'],
  inputs: ['model'],
  providers: [
    { provide: BaseValidatorService, useExisting: WebFormsBaseValidatorService }
  ]
})
@dataTransfer(['valSummary'])
@ExceptionHandlerClass(ErrorCodes.Winforms)
export class ValidationSummaryComponent
  extends ControlComponent
  implements OnInit
{
  /**
   * Property with the errorMessages to be shown.
   *
   * @memberof ValidationSummaryComponent
   */
  private errorMessagesInternal: string[] = [];

  /**
   * Property with the header text.
   *
   * @memberof ValidationSummaryComponent
   */
  private headerTextInternal = '';

  /**
   * Property with the error message's display mode.
   *
   * @memberof ValidationSummaryComponent
   */
  private displayModeInternal: ValidationSummaryDisplayMode =
    ValidationSummaryDisplayMode.BulletList;

  /**
   * Property with the option to create an alert with the error list.
   *
   * @memberof ValidationSummaryComponent
   */
  private showMessageBoxInternal = false;

  /**
   * Property with the option to show the error messages.
   *
   * @memberof ValidationSummaryComponent
   */
  private showValidationErrorsInternal = true;

  /**
   * Property with validationGroup.
   *
   * @memberof ValidationSummaryComponent
   */
  private validationGroupInternal = '';

  /**
   * Base constructor of the component.
   *
   * @param wmService
   * @param refChange
   * @param render2
   * @param elem
   * @param webComponents
   * @param validatorService
   * @param bringTopServ1
   * @memberof ValidationSummaryComponent
   */
  constructor(
    private wmService: WebMapService,
    private refChange: ChangeDetectorRef,
    private render2: Renderer2,
    private elem: ElementRef,
    webComponents: WebComponentsService,
    private validatorService: BaseValidatorService,
    @Optional() private bringTopServ1: BringTopService
  ) {
    super(refChange, render2, elem, webComponents, bringTopServ1);
  }

  /**
   * angular ngOnInit lifehook.
   * Retrieves the error messages from the validator service.
   *
   * @memberof ValidationSummaryComponent
   */

  ngOnInit() {
    this.updateErrorMessages();
    this.validatorService.addValidationSummary(this);
  }

  /**
   * Gets/sets the headerText property.
   *
   * @memberof ValidationSummaryComponent
   */
  @Input()
  set headerText(text: string) {
    this.headerTextInternal = text;
  }

  get headerText() {
    return this.model.HeaderText ?? this.headerTextInternal;
  }

  /**
   * Gets/sets the showValidationErrors property.
   *
   * @memberof ValidationSummaryComponent
   */
  @Input()
  set showValidationErrors(value: boolean) {
    this.showValidationErrorsInternal = value;
  }

  get showValidationErrors() {
    return this.model.ShowValidationErrors ?? this.showValidationErrorsInternal;
  }

  /**
   * Gets/sets the displayMode property.
   *
   * @memberof ValidationSummaryComponent
   */
  @Input()
  set displayMode(value: ValidationSummaryDisplayMode) {
    this.displayModeInternal = value;
  }

  get displayMode(): ValidationSummaryDisplayMode {
    return this.model.DisplayMode ?? this.displayModeInternal;
  }

  /**
   * Gets the ValidationSummaryDisplayMode enum.
   *
   * @readonly
   * @type {typeof ValidationSummaryDisplayMode}
   * @memberof ValidationSummaryComponent
   */
  get validationSummaryDisplayMode(): typeof ValidationSummaryDisplayMode {
    return ValidationSummaryDisplayMode;
  }

  /**
   * Gets/sets the validationGroup.
   *
   * @memberof ValidationSummaryComponent
   */
  @Input()
  set validationGroup(value: string) {
    this.validationGroupInternal = value;
  }

  get validationGroup() {
    return this.model.ValidationGroup ?? this.validationGroupInternal;
  }

  /**
   * Gets/sets the showMessageBox property.
   *
   * @memberof ValidationSummaryComponent
   */
  @Input()
  set showMessageBox(value: boolean) {
    this.showMessageBoxInternal = value;
  }

  get showMessageBox() {
    return this.model.ShowMessageBox ?? this.showMessageBoxInternal;
  }

  /**
   * Gets/sets the visible property.
   *
   * @memberof ValidationSummaryComponent
   */
  @Input()
  set visible(value: boolean) {
    super.visible = value;
    if (this.showMessageBox && this.visible) {
      switch (this.displayMode) {
        case ValidationSummaryDisplayMode.List:
          alert(`${this.headerText}\n${this.formatErrorMessages('\n')}`);
          break;
        case ValidationSummaryDisplayMode.SingleParagraph:
          alert(`${this.headerText}\n${this.formatErrorMessages(', ')}`);
          break;
        default:
          alert(`${this.headerText}\n- ${this.formatErrorMessages('\n- ')}`);
          break;
      }
    }
  }

  get visible() {
    return this.model.Visible ?? super.visible;
  }

  /**
   * Gets the error messages property
   *
   * @memberof ValidationSummaryComponent
   */
  get errorMessages() {
    return this.errorMessagesInternal;
  }

  /**
   * Gets the hidden property
   * Should be hidden if either the visible or the showValidationErrors are set to false.
   *
   * @memberof ValidationSummaryComponent
   */

  get hidden() {
    return !this.visible || !this.showValidationErrors;
  }

  /**
   * join the error messages with the given separator.
   *
   * @memberof ValidationSummaryComponent
   * @returns a string with the error messages
   */
  formatErrorMessages(separator: string): string {
    return this.errorMessagesInternal.join(separator);
  }

  /**
   * Updates the array of error messages.
   *
   * @memberof ValidationSummaryComponent
   */
  updateErrorMessages(): void {
    this.errorMessagesInternal = this.validatorService.getActiveErrorMessages(
      this.validationGroup
    );
  }
}
<div *ngIf="displayMode == validationSummaryDisplayMode.BulletList && !hidden" [ngClass]="class">
    {{headerText}}
    <ul>
        <li *ngFor="let errorMessage of errorMessages">
            {{errorMessage}}
        </li>
    </ul>
</div>

<div *ngIf="displayMode == validationSummaryDisplayMode.List && !hidden" [ngClass]="class">
    {{headerText}}
    <div *ngFor="let errorMessage of errorMessages">
        {{errorMessage}}
        <br>
    </div>
</div>


<div *ngIf="displayMode == validationSummaryDisplayMode.SingleParagraph && !hidden" [ngClass]="class">
    {{headerText}} {{formatErrorMessages(', ')}}
</div>

./validation-summary.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""