In my application I want to apply compose validator conditionally and respective validators. I did with custom validator but doesn't get success.
this.myForm = this.builder.group({
country:['',Validators.required],
age:['',Validators.required],
dependentName:['',Validators.compose([Validators.maxLength(20), Validators.required])]
})
- If country is 'America' and age is less than 18 then dependentName is required and max length should be 20.
- If the country is other than 'America' then dependentName field is not required but maxlength should be 20.
Please help.