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.

Change in FormJson dynamically doesn't update Form

See original GitHub issue

Hi,

I modified the ng2-formio start kit and added a button to update the form schema json. <button class="btn btn-primary" (click)="addControl()"> Add Control </button>

`addControl() { var data = { ‘type’: ‘textfield’, ‘input’: true, ‘tableView’: true, ‘inputType’: ‘text’, ‘inputMask’: ‘’, ‘label’: ‘Last Name’, ‘key’: ‘lastName’, ‘placeholder’: ‘Enter your last name’, ‘prefix’: ‘’, ‘suffix’: ‘’, ‘multiple’: false, ‘defaultValue’: ‘’, ‘protected’: false, ‘unique’: false, ‘persistent’: true, ‘validate’: { ‘required’: true, ‘minLength’: 2, ‘maxLength’: 10, ‘pattern’: ‘’, ‘custom’: ‘’, ‘customPrivate’: false }, ‘conditional’: { ‘show’: ‘’, ‘when’: null, ‘eq’: ‘’ } };

this.formJson.components.push(data);

};`

It doesn’t update the form dynamically. Am I missing anything??

Thanks, Aniket

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
travistcommented, Dec 14, 2017

You can include an event emitter as an input to the refresh property like so.

<formio [refresh]="triggerRefresh" ....></formio>

Then in your controller do the following.

this.triggerRefresh = new EventEmitter();

this.triggerRefresh.emit({
  property: 'form',
  value: newFormObject
});
0reactions
rohitsiddhacommented, Apr 17, 2020

@ahka01 , Thanks for the reply. The problem isn’t with updating the form and submission data. It works as expected. I’m talking about the form change event callback. If you inspect the object you get when form change event triggers, you’ll see previous as well as new form submission keys in the data object.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rules not getting applied when data changed dynamically ...
It doesn't work because the change detection of JSON Forms is bypassed. JSON Forms will properly update when the data changed via two...
Read more >
Create dynamic form based on json file (json file can be ...
I am trying to create a dynamic form based on https://angular.io/guide/dynamic-form. I'm using a json file to create dynamic form. i am having...
Read more >
Three Ways to Dynamically Alter your Form Validation in ...
Now, let's say the user doesn't mark optionB and submits the form. The form will still be invalid even though, from our perspective,...
Read more >
Creating Dynamic Angular Forms with JSON - Elite Ionic
In this tutorial, we walk through how to build a dynamic Angular form from a JSON data source.
Read more >
Dynamically configuring AG Grid headers from JSON API data
In this blog post we will show how to dynamically configure and read a JSON object from API calls into AG Grid. We...
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