@@ -17,31 +17,34 @@ import { controlCssClass, controlFlow, controlValidators } from '../utils/contro
1717 styleUrls : [ ] ,
1818} )
1919export class GodzillaFormsParserComponent implements OnChanges {
20- @Input ( ) jsonForm : GodzillaForm | undefined ;
20+ @Input ( ) form : GodzillaForm | undefined ;
21+
22+ @Input ( ) jsonForm : string | undefined ;
2123
2224 @Input ( ) enableGridSystem : boolean = true ;
2325
2426 @Output ( ) readonly validData : EventEmitter < any > = new EventEmitter < any > ( ) ;
2527
2628 submitted = false ;
2729
28- readonly form : FormGroup = this . formBuilder . group ( { } ) ;
30+ readonly formGroup : FormGroup = this . formBuilder . group ( { } ) ;
2931
3032 constructor ( private formBuilder : FormBuilder , private godzillaLoader : GodzillaLoaderService ) { }
3133
3234 // eslint-disable-next-line @typescript-eslint/no-unused-vars
3335 ngOnChanges ( changes : SimpleChanges ) {
34- if ( this . jsonForm ) {
35- this . createPages ( this . jsonForm . pages ) ;
36+ if ( this . form || this . jsonForm ) {
37+ this . form = this . form || ( JSON . parse ( this . jsonForm || '' ) as GodzillaForm ) ;
38+ this . createPages ( this . form . pages ) ;
3639 }
3740 }
3841
3942 /**
4043 * Public function to notify the parser component to reset the form
4144 */
4245 public notifyFormChanged ( ) {
43- if ( this . jsonForm ) {
44- this . createPages ( this . jsonForm . pages ) ;
46+ if ( this . form ) {
47+ this . createPages ( this . form . pages ) ;
4548 }
4649 }
4750
@@ -51,8 +54,8 @@ export class GodzillaFormsParserComponent implements OnChanges {
5154 */
5255 public validate ( ) {
5356 this . submitted = true ;
54- if ( this . form . valid ) {
55- this . validData . emit ( this . form . getRawValue ( ) ) ;
57+ if ( this . formGroup . valid ) {
58+ this . validData . emit ( this . formGroup . getRawValue ( ) ) ;
5659 }
5760 }
5861
@@ -63,7 +66,7 @@ export class GodzillaFormsParserComponent implements OnChanges {
6366 * @private
6467 */
6568 getFormControllerById ( id : string ) {
66- return this . form . get ( id ) ;
69+ return this . formGroup . get ( id ) ;
6770 }
6871
6972 /**
@@ -75,11 +78,11 @@ export class GodzillaFormsParserComponent implements OnChanges {
7578 // eslint-disable-next-line no-restricted-syntax
7679 for ( const page of pages ) {
7780 // eslint-disable-next-line no-continue
78- if ( this . jsonForm ?. style . type === GodzillaFormType . classic ) {
79- this . createForm ( page . controls , this . form ) ;
81+ if ( this . form ?. style . type === GodzillaFormType . classic ) {
82+ this . createForm ( page . controls , this . formGroup ) ;
8083 } else {
8184 const group = this . formBuilder . group ( { } ) ;
82- this . form . addControl ( page . id , group ) ;
85+ this . formGroup . addControl ( page . id , group ) ;
8386 }
8487 }
8588 }
0 commit comments