infinum / eightshift-forms

WordPress plugin project for Gutenberg forms
https://eightshift.com
Other
29 stars 5 forks source link

[BUG] - Form state keys should be generated so that multiple instances of the same form can exist on a page #451

Open mbmjertan opened 2 months ago

mbmjertan commented 2 months ago

Currently, Forms uses the form ID as a state key. Example: https://github.com/infinum/eightshift-forms/blob/main/src/Blocks/components/form/assets/state-init.js#L923

If you put more than one instance of the same form on the page, all instances below the first one in the DOM will break (and potentially, even the first instance will) - because they unexpectedly share state.

This results at least in fields not being initialized properly (e.g. Choices doesn't get initialized at all in the second form etc.).

I think we can work around this by giving each form a unique key and using that as the state key.