UNPKG

bia-framework

Version:

Bia Framework to work with angular 2

39 lines (34 loc) 1.37 kB
import {Directive, Host, Attribute, OnInit, Optional} from "@angular/core"; import {Validators} from "@angular/forms"; import {CoreFormControlBase} from "../CoreFormControlBase"; import {CoreFormInput} from "../core-form-input/core-form-input.component"; import {CoreFormDropDown} from "../core-form-dropdown/core-form-dropdown"; // const provideParent = // ( component:any, parentType?:any ) => // { // return {provide: parentType || CoreFormInput, useExisting: forwardRef(() => component)}; // }; @Directive( { selector: 'validation-required' } ) export class CoreFormValidationRequired implements OnInit { private host:CoreFormControlBase; ngOnInit():any { if (this.host != null) this.host.addFormValidator({ ValidationName: 'required', ValidationMessage: this.validationRequiredMessage }, Validators.required); return undefined; } constructor( @Optional() @Host() private inputHost:CoreFormInput, @Optional() @Host() private dropDownHost:CoreFormDropDown, @Attribute("message") private validationRequiredMessage:string ) { this.host = inputHost || dropDownHost; } }