Guest User

Untitled

a guest
Mar 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. <ion-input *ngIf="property.component == 'number'"
  2. type="number" [attr.id]="property.id"
  3. [formControlName]="property.label">
  4. </ion-input>
  5.  
  6. private createFormGroup = (question: SurveyQuestion) => {
  7.  
  8. const formGroup = this.formBuilder.group({
  9. [question.label]: this.formBuilder.array([])
  10. });
  11. const items = formGroup.get(question.label) as FormArray;
  12. question.properties.forEach((property, index) => {
  13.  
  14. let validatorArray = [];
  15.  
  16. if (!property.is_optional)
  17. {
  18. validatorArray.push(Validators.required);
  19. }
  20.  
  21. //Other validators are added to array here
  22.  
  23. items.push(this.formBuilder.group({
  24. [property.label]: new FormControl("", Validators.compose(validatorArray))
  25. }))
  26. });
  27.  
  28. return formGroup;
  29.  
  30. };
Add Comment
Please, Sign In to add comment