[BUG] Formio.options.form leads to interference between differnt forms
When creating a new form, the following line of code copies the global formio options into the options for the new form:
https://github.com/formio/formio.js/blob/2956bac406b7823291f993cc49f8242e628d8282/src/Form.js#L28
But this is only a shallow copy. If we for example set Formio.options.form.hooks = {} all forms will share a single hooks-object. If we further create a builder instance, the builder will pollute this global hooks object with builder hooks leading all masks to behave partly like builders (especially all components will be displayed as in the builder with the edit toolbar at the top right).
The obvious solution would be to just introduce a fastCloneDeep, however this may also lead to undesired consequences. Maybe the user actually wanted to have all forms share a single i18next or events objects. In fact fastCloneDeep would crash trying to copy i18next, since it is cyclic.
I think a good solution would be be to allow options or options.form to be a function, which can return as shallow or deep a copy as desired. This would also require adapting the code for merging several global options from different plugins. Currently this is simply the following:
https://github.com/formio/formio.js/blob/2956bac406b7823291f993cc49f8242e628d8282/src/formio.form.js#L58
I think the default behaviour if an object instead of a function is given should be to create a deep copy, but maybe for backwards compatibility one would keep the current behaviour.
We're currently addressing a backlog of GitHub issues. Closing this thread as it is outdated. Please re-open if it is still relevant. Thank you for your contribution!
I don't think I am able to reopen myself. At any rate this issue should still be present since the quoted code did not change.
thanks @juliapath I'll go ahead and reopen this and see if we can get it prioritized sometime soon. Truth be told from just glancing at this I worry about the backwards compatibility problems that may be introduced by changing the options API to a function; however, PRs are absolutely welcome if you want to contribute and feel like taking a stab at this!
Backwards compatibility shouldn't be a problem if the old behaviour is retained if Formio.options isn't a function, right?
I'll see if I can get around to making a PR. Shouldn't be that much work.
Backwards compatibility shouldn't be a problem if the old behaviour is retained if Formio.options isn't a function, right?
Yeah, I must have misunderstood your original comment.
I'll see if I can get around to making a PR. Shouldn't be that much work.
Great, thanks!