question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[td-dynamic-forms] [Question] [Usage example] - How do you retrieve data from dynamic form?

See original GitHub issue

Hey,

Could someone give me an idea how to properly retrieve data from <td-dynamic-forms> component?

What I tried so far is using a @ViewChild to get FormGroup:

  @ViewChild(TdDynamicFormsComponent) form: TdDynamicFormsComponent;

and then I was subscribing to valueChanges.

  ngAfterViewInit() {
    this.form.form.valueChanges.subscribe( (val) => {
      this.change.emit(val);
    });
  }

it works, until I change the property [elements] to different value: <td-dynamic-forms [elements]="newArrayOfElements"> </td-dynamic-forms>

then I get an error: There is no FormControl instance attached to form control element with name: xxx

Any suggestions on that?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
natejgardnercommented, Aug 22, 2017

I got some support over email that solved my problem. Here’s the code that’s needed:

<td-dynamic-forms #myForm></td-dynamic-forms>
@ViewChild('myForm')
_myForm: TdDynamicFormsComponent

printFormData() {
    console.log(this._myForm.value);
    }

It would be helpful in the docs if the code could be extended with something like this:

form: ITDynamicElementConfig[] = [{
    name: "inputField",
    type: TdDynamicElement.Input,
    label: "Input Field",
    required: true
}]

@ViewChild('myForm')
_myForm: TdDynamicFormsComponent

currentValue: string;

submit() {
    if(this._myForm) {
    let this.currentValue = this._myForm.value.inputField;
    }}
<td-dynamic-forms [elements]="form" #myForm></td-dynamic-forms>
<button (click)='submit()'>SUBMIT</button>
<h3>Your inputField value is:</h3> {{this.currentValue}}

This way developers can easily see the intended way of accessing data in the documentation. Right now, there’s a submit button but it’s not hooked up to anything. The creation of forms is intuitive, but accessing them isn’t very straightforward at all.

1reaction
jayjiehcommented, Mar 6, 2018

<ng-template let-param ngFor [ngForOf]=“params”>
<td-dynamic-forms [elements]=“param.elements” #paramform> <ng-template let-element ngFor [ngForOf]=“param.elements”> <ng-template let-control=“control” [tdDynamicFormsError]=“element.name”> <span *ngIf=“control.touched || !control.pristine”> <span *ngIf=“control.hasError(‘required’)”>Required</span> <span *ngIf=“control.hasError(‘min’)”>Min value: {{element.min}}</span> <span *ngIf=“control.hasError(‘max’)”>Max value: {{element.max}}</span> <span *ngIf=“control.hasError(‘minlength’)”>Min length value: {{element.minLength}}</span> <span *ngIf=“control.hasError(‘maxlength’)”>Max length value: {{element.minLength}}</span> </span> </ng-template> </ng-template> </td-dynamic-forms> </ng-template>

how do I get the form values from the multiple forms generated, Now I can only get the first form’s value only. I want to get even if they are 10 forms dynamically generated

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Dynamic Forms & Get Data from ... - Vipin Vijayan
Let's create a dynamic List based on the counter with each form having a TextField. _row(int index) { return Row( children: [ Text('ID:...
Read more >
Salesforce Dynamic Forms: Overview & Deep Dive Tutorial
Dynamic Forms are available now! Simply go to the Lightning record page of a custom object and select the “Highlights Panel” or the...
Read more >
Building dynamic forms - Angular
In this tutorial you will build a dynamic form that presents a basic questionnaire. You build an online application for heroes seeking employment....
Read more >
How To Build Dynamic Forms - Appsmith - YouTube
This video explains how to build dynamic forms in Appsmith using the List widget. The also explains how to extract input data from...
Read more >
Create Dynamic Microsoft Form and Process Response using ...
In this video, I will show how to create a dynamic (conditional) Microsoft Form using section and branching. I will use a Product...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found