bia-framework
Version:
Bia Framework to work with angular 2
57 lines (46 loc) • 1.51 kB
text/typescript
import {Control} from "@angular/common";
import {Attribute, Host, ElementRef, Input, OnInit, Directive} from "@angular/core";
import {OdisseiaInput} from "../odisseia-input/odisseia-input";
/**
* Created by jd on 08/03/2016.
*/
({
selector: 'match-validation'
})
export class MatchValidation implements OnInit
{
()
match:Control;
static matchValue:Object;
static value:Object;
constructor(()
private controlHost:OdisseiaInput,
('message')
private validationMessage:string,
el:ElementRef)
{
this.controlHost.addFormValidator({ValidationName: 'match-validation', ValidationMessage: this.validationMessage}, MatchValidation.matchValidation);
}
ngOnInit():any
{
this.match.valueChanges.subscribe((a)=>
{
MatchValidation.matchValue = a;
this.controlHost.control.updateValueAndValidity();
});
return undefined;
}
static matchValidation(c:Control):{ [s: string]: boolean }
{
console.log("Is valid ? = " + (MatchValidation.matchValue == c.value).toString());
if (MatchValidation.matchValue != null && c.value != null)
{
if (MatchValidation.matchValue == c.value)
return null;
else
return {"match": true};
}
else
return null;
}
}