Ticket #13137 (confirmed Bug)
form_tabbing.js is not defensive against multiple initializations
Reported by: | seanupton | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 4.x |
Component: | JavaScript | Version: | 4.2 |
Keywords: | Cc: |
Description (last modified by seanupton) (diff)
Multiple calls of ploneFormTabbing.initialize() in JavaScript, whether by design or accident will lead to duplicative ul.formTabs in the DOM for a form. I have ested this with z3c.form on Dexterity add forms.
Duplication (not sure why this triggers multiple intialization, this is an edge case, but the point is that the JS should be more defensive):
- Create a custom add form class and add view class for a Dexterity type. Set a custom template attribute on the add form class, and in that template, include <metal:block use-macro="context/@@ploneform-macros/titlelessform" />. Register view fronting for the form in ZCML as a normal browser view, then...
- Visit that browser view with ?ajax_load=1&ajax_include_head=1 in the query string.
In doing this, I see two stacked sets of form tabs for one form. The point isn't my (edge-case) form setup, but the fact that form_tabbing does not clear state before re-initializing. In my template I add a JS snippet to work around this:
jq('ul.formTabs').remove(); ploneFormTabbing.initialize();
We really should make form_tabbing.js defensive, clearing all form tabs for all forms on page before completely re-initializing them.
Updated javascript for workaround, (correctly) use remove() instead of empty().