Skip to content

BaseComponent

reference
1 min readUpdated

Kind: Class

Source: Pams/Web/portal/pams-web/src/app/components/core/base.component.ts (line 8)

Part of: Pams Web

BaseComponent centralizes keyboard handling, validation, and form submission behavior for portal components. Subclasses can add validation rules through customValidate() and respond to validation completion with onValidated(), while isValid() and validationError() expose validation state.

Methods

MethodSignatureReturns
handleKeyboardEventhandleKeyboardEvent(event: KeyboardEvent)void
validatevalidate(groupNames: string[])void
validateControlvalidateControl(controlName: string, groupNames: string[])void
isValidisValid(controlName: string)boolean
validationErrorvalidationError(controlName: string)any
onValidatedonValidated()void
submitsubmit()void
submitFormsubmitForm()void
customValidatecustomValidate()void

Properties

PropertyType
_modelBehaviorSubject<T>
loadingboolean
validatedany

Diagram

mermaid
graph LR
  KeyboardEvent[Keyboard event] --> Handle[handleKeyboardEvent()]
  Handle --> Submit[submit()]
  Submit --> SubmitForm[submitForm()]
  SubmitForm --> Validate[validate()]
  Validate --> ValidateControl[validateControl()]
  Validate --> CustomValidate[customValidate()]
  Validate --> OnValidated[onValidated()]
  Validate --> IsValid[isValid()]
  Validate --> ValidationError[validationError()]

Usage

ts
import { BaseComponent } from 'src/app/components/core/base.component';

export class ProfileFormComponent extends BaseComponent {
  save(): void {
    this.submitForm();

    if (!this.isValid()) {
      console.error(this.validationError());
    }
  }

  customValidate(): void {
    // Add component-specific validation rules here.
  }

  onValidated(): void {
    // React after validation has completed.
  }
}

AI Coding Instructions

  • Extend BaseComponent for components that need shared validation and submission behavior.
  • Put component-specific validation rules in customValidate() instead of duplicating validation flow in submit handlers.
  • Check isValid() before acting on submitted data and use validationError() when displaying or logging validation failures.
  • Keep onValidated() focused on post-validation actions; do not bypass validate() or submitForm() with separate form flows.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • LoginFormComponentPams/Web/portal/pams-web/src/app/components/core/login-form/login-form.component.ts:1

Was this page helpful?

Download as PDF