Form validation Angular 4 | multi-field validation | Set error on empty Field depending on other field
Form validation Angular 4 | multi-field validation | Set error on empty Field depending on other field I have a form where two fields (' From date ' and ' To Date ') are there along with other fields. Requirement: User can provide only ' From Date ' If both date are given ' From date ' must NOT be greater than ' To Date '; if given ' To Date ' will be underlined with Red. If one provides ' To Date ' only, then the ' From Date ' will be underlined with Red. To do this I used a frombuilder 'SrchForm' like this: myForm(){ this.srchGrp = this.SrchForm.group({ //other FormcontrolNames from_date : '', // from_date controlname for 'From Date' field to_date : '', // to_date controlname for 'To Date' field }, {validator: this.fromNtoValidate('from_date', 'to_date')}) } And, fromNtoValidate(from_date, to_date){ return (group: FormGro...