File

projects/common/lib/components/city/city.component.ts

Extends

AbstractFormControl

Implements

OnInit ControlValueAccessor

Metadata

selector common-city
templateUrl ./city.component.html

Index

Properties
Methods
Inputs
Outputs
Accessors

Constructor

constructor(controlDir: NgControl)
Parameters :
Name Type Optional
controlDir NgControl No

Inputs

label
Type : string
Default value : 'City'
labelforId
Type : string
Default value : 'city_' + this.objectId
maxlength
Type : string
Default value : '100'
placeholder
Type : string
Default value : 'City name'
required
Type : boolean
Default value : false
value
Type : string
disabled
Type : boolean
Default value : false
Inherited from AbstractFormControl
errorMessage
Type : ErrorMessage
Inherited from AbstractFormControl
label
Type : string
Inherited from AbstractFormControl

Outputs

blur
Type : EventEmitter<any>
valueChange
Type : EventEmitter<string>

Methods

ngOnInit
ngOnInit()
Returns : void
onBlur
onBlur(event: any)
Parameters :
Name Type Optional
event any No
Returns : void
onValueChange
onValueChange(value: string)
Parameters :
Name Type Optional
value string No
Returns : void
writeValue
writeValue(value: string)
Parameters :
Name Type Optional
value string No
Returns : void
ngOnInit
ngOnInit()
Inherited from AbstractFormControl
Returns : void
registerOnChange
registerOnChange(fn: any)
Inherited from AbstractFormControl
Parameters :
Name Type Optional
fn any No
Returns : void
registerOnTouched
registerOnTouched(fn: any)
Inherited from AbstractFormControl
Parameters :
Name Type Optional
fn any No
Returns : void
Protected registerValidation
registerValidation(ngControl: NgControl, fn: ValidationErrors)
Inherited from AbstractFormControl

Register self validating method

Parameters :
Name Type Optional Description
ngControl NgControl No
fn ValidationErrors No

function for validating self

Returns : any
setDisabledState
setDisabledState(isDisabled: boolean)
Inherited from AbstractFormControl
Parameters :
Name Type Optional
isDisabled boolean No
Returns : void
Protected setErrorMsg
setErrorMsg()
Inherited from AbstractFormControl
Returns : void
Private validateLabel
validateLabel()
Inherited from AbstractFormControl
Returns : void
Abstract writeValue
writeValue(value: any)
Inherited from AbstractFormControl
Parameters :
Name Type Optional
value any No
Returns : void

Properties

_defaultErrMsg
Type : ErrorMessage
Default value : { required: LabelReplacementTag + ' is required.', invalidChar: LabelReplacementTag + ' must contain letters and may include numbers and special characters ' + 'such as hyphens, periods, apostrophes and blank characters.', maxlength: LabelReplacementTag + ' exceeds the maximum number of allowable characters.' }
city
Type : string
Default value : ''
Public controlDir
Type : NgControl
Decorators :
@Optional()
@Self()
Abstract _defaultErrMsg
Type : ErrorMessage
Default value : {}
Inherited from AbstractFormControl
_onChange
Default value : () => {...}
Inherited from AbstractFormControl
_onTouched
Default value : () => {...}
Inherited from AbstractFormControl
Public objectId
Type : string
Default value : UUID.UUID()
Inherited from Base
Defined in Base:11

An identifier for parents to keep track of components

Accessors

value
getvalue()
setvalue(val: string)
Parameters :
Name Type Optional
val string No
Returns : void

Design Guidelines

Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente, magnam ipsam. Sit quasi natus architecto rerum unde non provident! Quia nisi facere amet iste mollitia voluptatem non molestias esse optio?

Aperiam fugiat consectetur temporibus, iste repellat, quisquam sapiente nisi distinctio optio, autem nemo tenetur error eum voluptatibus ab accusamus quis voluptatum blanditiis. Quam et ut reprehenderit vitae nobis, at ipsum!

Exercitationem pariatur animi repudiandae corporis obcaecati ratione ducimus beatae quam, nostrum magnam unde numquam quidem cupiditate odit id. Beatae alias molestiae, optio incidunt harum quia voluptates deserunt sequi. Nesciunt, optio.

import { Component, OnInit, Input, Output, EventEmitter, Optional, Self } from '@angular/core';
import { ControlValueAccessor, NgControl } from '@angular/forms';
import { AbstractFormControl } from '../../models/abstract-form-control';
import { ErrorMessage, LabelReplacementTag } from '../../models/error-message.interface';

@Component({
  selector: 'common-city',
  templateUrl: './city.component.html',
})
export class CityComponent extends AbstractFormControl implements OnInit, ControlValueAccessor  {

  @Input() label: string = 'City';
  @Input() maxlength: string = '100';
  @Input() labelforId: string = 'city_' + this.objectId;
  @Input() placeholder: string = 'City name';
  @Input() required: boolean = false;

  @Input()
  set value( val: string ) {
    if ( val ) {
      this.city = val;
    }
  }
  get value() {
    return this.city;
  }

  @Output() valueChange: EventEmitter<string> = new EventEmitter<string>();
  @Output() blur: EventEmitter<any> = new EventEmitter<any>();

  city: string = '';

  _defaultErrMsg: ErrorMessage = {
    required: LabelReplacementTag + ' is required.',
    invalidChar: LabelReplacementTag + ' must contain letters and may include numbers and special characters ' +
                 'such as hyphens, periods, apostrophes and blank characters.',
    maxlength: LabelReplacementTag + ' exceeds the maximum number of allowable characters.'
  };

  constructor( @Optional() @Self() public controlDir: NgControl ) {
    super();
    if ( controlDir ) {
      controlDir.valueAccessor = this;
    }
  }

  ngOnInit() {
    super.ngOnInit();
  }

  onValueChange( value: string ) {
    this.city = value;
    this._onChange( value );
    this.valueChange.emit( value );
  }

  onBlur( event: any ) {
    this._onTouched( event );
    this.blur.emit( event );
  }

  writeValue( value: string ): void {
    if ( value !== undefined ) {
      this.city = value;
    }
  }
}
<label for="{{labelforId}}">{{label}}</label>
<input class="form-control"
       spellcheck="false"
       type="text"
       id="{{labelforId}}"
       [value]="city"
       (change)="onValueChange($event.target.value)"
       (blur)="onBlur($event)"
       [disabled]="disabled"
       [required]="required"
       [attr.maxlength]="maxlength"
       [placeholder]="placeholder"
       autocomplete="off"/>

 <!-- Error messages for input -->
<common-error-container
    [displayError]="controlDir && !disabled && (controlDir.touched || controlDir.dirty) && controlDir.errors">
  <div *ngIf="controlDir.errors?.required">
    {{_defaultErrMsg.required}}
  </div>
  <div *ngIf="controlDir.errors?.invalidChar">
    {{_defaultErrMsg.invalidChar}}
  </div>
  <div *ngIf="controlDir.errors?.maxlength">
    {{_defaultErrMsg.maxlength}}
  </div>
</common-error-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""