jsonform / jsonform

Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.
https://jsonform.github.io/jsonform/playground/index.html
MIT License
2.72k stars 553 forks source link

Question: how to update data in the form? #405

Closed pruchay closed 1 year ago

pruchay commented 1 year ago

Hi :) I want to create two tabs with two different libraries (one for regular users and one for tech users). In the regular tab will be placed jsonform and in the tech tab jsoneditor.

When the user will be switching between tabs, I need to pass data from one tab to another. Currently, it works, but when I switch from the jsoneditor tab to the tab with jsonform I have a problem - data in the form is not updated - it's just creating a new form.

So, is it possible to update a form that already exists instead of creating a new one?

For updating data in the form, I use this code:

      const setFormData = data => {
        $('#jsonForm').jsonForm({
          value: data,
          ...jsonFormSchema,
        })
      }

Update 1: Aa a quick solution I used document.getElementById('jsonForm').innerHTML = '', but maybe there is built in solution?

Update 2: But this lead to a bug - I can't expand grouped fields.

tchapi commented 1 year ago

Hi, I would reckon that you need to instantiate your form once, and then update the data as you need when you switch between tabs.

.jsonForm() creates a form. You need to use standard JS to update a field

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.