Last active
May 14, 2019 12:43
-
-
Save shantanuhashtaag/dcff10c8f980012ec593e53905977002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ngOnInit() { | |
| this.form = this.fb.group({ | |
| 'Xs': this.fb.array([ | |
| this.initX() | |
| ]) | |
| }); | |
| this.form.valueChanges.subscribe(data => this.validateForm()); | |
| this.validateForm(); | |
| } | |
| initX() { | |
| return this.fb.group({ | |
| // ---------------------forms fields on x level ------------------------ | |
| 'X': ['X', [Validators.required, Validators.pattern('[0-9]{4}')]], | |
| // --------------------------------------------------------------------- | |
| 'Ys': this.fb.array([ | |
| this.initY() | |
| ]) | |
| }); | |
| } | |
| initY() { | |
| return this.fb.group({ | |
| // ---------------------forms fields on y level ------------------------ | |
| 'Y1': ['Y1', [Validators.required, Validators.pattern('[0-9]{4}')]], | |
| 'Y2': ['Y2', [Validators.required, Validators.pattern('[0-9]{4}')]], | |
| // --------------------------------------------------------------------- | |
| 'Zs': this.fb.array([ | |
| this.initZ() | |
| ]) | |
| }) | |
| } | |
| initZ() { | |
| return this.fb.group({ | |
| // ---------------------forms fields on z level ------------------------ | |
| 'Z': ['Z', [Validators.required, Validators.pattern('[0-9]{4}')]], | |
| // --------------------------------------------------------------------- | |
| }) | |
| } | |
| addX() { | |
| const control = <FormArray>this.form.controls['Xs']; | |
| control.push(this.initX()); | |
| } | |
| addY(ix) { | |
| const control = (<FormArray>this.form.controls['Xs']).at(ix).get('Ys') as FormArray; | |
| control.push(this.initY()); | |
| } | |
| addZ(ix, iy) { | |
| const control = ((<FormArray>this.form.controls['Xs']).at(ix).get('Ys') as FormArray).at(iy).get('Zs') as FormArray; | |
| control.push(this.initZ()); | |
| } | |
| constructor(private fb: FormBuilder) { | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment