Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Rendering of Fields/Labels When Setting Form Submission on Initial Load #5598

Open
fuadkhan1996 opened this issue May 14, 2024 · 5 comments

Comments

@fuadkhan1996
Copy link

Describe the bug
After updating to the latest version of Formio.js, I am experiencing an issue where form fields and labels are rendered twice when setting the form submission data during the initial load of the form. This issue occurs consistently when using the this.form.submission = { data: data } method right after creating the form. Removing this line results in the form rendering correctly, suggesting that the issue is directly related to setting the submission data

Version/Branch
4.19.2

To Reproduce
Steps to reproduce the behavior:

  1. Create a form using Formio.createForm().
  2. Immediately set the form submission using this.form.submission = { data: data }.
  3. Observe that most of the form fields and labels are rendered twice.

Expected behavior
Setting the form submission data should only update the form fields with the provided data without causing any additional rendering issues.

Screenshots
image
image

Additional context
The form fields and labels are duplicated, indicating an extra rendering process is triggered when the form submission is set on the initial load. It's working fine on version 4.16.0.

@brendanbond
Copy link
Contributor

Hi @fuadkhan1996 thanks for reporting this, although I'm unable to reproduce this issue using version 4.19.2. Can you fork the JSFiddle I've provided and help us out with a minimal reproducible example?

@jamie-steele
Copy link

jamie-steele commented Jul 11, 2024

Wanted to post this as I also ran into the issue and found a solution.

I was originally assigning the data in the same way and was able to replicate the problem, I changed my code to loop through all my properties in the source object and simply assign them.

I am wondering if the cause is something to do with when your assigning this way and you have a missing property in your source it makes form.io think its missing and it readds it when rendering.

In my specific example it was HTML components which we didn't have in the form JSON data.

Before

function CombineData(form, formDataJson) {
    form.submission = { data: formDataJson };
}

After

function CombineData(form, formDataJson) {
    for (const key in formDataJson) {
        if (formDataJson.hasOwnProperty(key)) {
            if (formDataJson[key] === "[object Object]") {
                // Ignore incorrectly serialized objects
                console.log(`Detected [object Object] at key: ${key}`);
                form.submission.data[key] = "";
            } else {
                form.submission.data[key] = formDataJson[key];
            }
        }
    }
}

@brendanbond
Copy link
Contributor

Hi @jamie-steele would you be willing to post your custom component ?

@fuadkhan1996
Copy link
Author

fuadkhan1996 commented Oct 21, 2024

Hi @brendanbond, I have the example set for you. I don't know what the possible solution can be but this is the bug in all the versions starting from 4.19.2.

https://jsfiddle.net/fuadk/28yrxapg/7/

@brendanbond
Copy link
Contributor

brendanbond commented Oct 21, 2024

Hey @fuadkhan1996 you can find more details about this issue in the description for #5792 - the markup in your HTML component is invalid, which causes the renderer to miss the attach phase for the first pass and just pop it into the DOM outside of any formio containers. Change the parent element to something like <div /> and it should work as expected.

github-merge-queue bot pushed a commit to bcgov/SIMS that referenced this issue Oct 24, 2024
The issue happened because the markup in the HTML component is invalid.
The "p" tag could not be used with children elements like: address,
article, aside, blockquote, details, dialog, div, dl, fieldset,
figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header,
hgroup, hr, main, menu, nav, ol, p, pre, search, section, table, or ul.

Form.io changed its default parent tag from p to div:
formio/formio.js#5792

Similar issue and developer explanation/recommendation:
formio/formio.js#5598 (comment)

Found some other issues not reported in the ticket as this one:

![image](https://github.com/user-attachments/assets/9ce4b90e-605b-48f9-9f8d-b73f220f2f4d)

- Checked all form.io forms;
- Changed the "p" tag to "div" when the component had invalid children
tags for paragraph;
- Changed some other invalid HTML found when doing the check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants