I am generating a form in Angular2/Ionic2 and I have followed the dynamic form tutorial on the Angular site. However, for my needs, I need more validations instead of just required. Hence this code.
doGenerateKidsBasicFormWithNameAndAge(params: any){
let kidsData:any = {};
params.forEach(question => {
kidsData[question.id] = this.doDecideValidation(question)
});
return new FormGroup(kidsData);
}
This is the function that decideds what type of validation will be applied.
doDecideValidation(question){
if(question.type === "text"){
new FormControl(question || '', Validators.compose([Validators.required, Validators.minLength(question.minLength), Validators.maxLength(question.maxLength), Validators.pattern('[a-zA-Z ]*')]));
}else if(question.type === "number"){
new FormControl(question || '', Validators.compose([Validators.required]));
}else {
new FormControl(question || '');
}
};
When I do this, I get an error.
TypeError: Cannot read property 'setParent' of undefined
Any ideas?