Addition: I am aware of a setParent(){} method. But Angular's documentation
is pretty slim on it. Docs Here
<https://angular.io/docs/ts/latest/api/common/index/AbstractControl-class.html#!#setParent-anchor>
On Wednesday, August 17, 2016 at 5:13:54 PM UTC+2, Andrew Graham-Yooll
wrote:
>
> I am generating a form in Angular2/Ionic2 and I have followed the dynamic
> form tutorial
> <https://angular.io/docs/ts/latest/cookbook/dynamic-form.html> 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?
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.