-
Notifications
You must be signed in to change notification settings - Fork 162
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
Accordion and SequenceWidget #347
Comments
This is quite a coincidence! I just ran into this problem myself and was actually coming here for the first time to post a fix. The problem is that the 'a' tag in the header of the mapping_accordion template uses a fixed value for the ID of the field which does not work inside a sequence since each new item is created with a dynamic ID. It seems that deform is smart enough to go through the ID elements of the sequenced template to update these but this misses the "#collapse-${field.oid}" in the href element of the 'a' tag in the header of the mapped object. My fix is to add an ID to the 'a' tag of the form: 'button-collapse-${field.oid}' and then add a simple javascript function, 'idgoto', which updates the href element of the tag using the ID of the element when the tag is clicked. Since the ID element is correctly updated this then updates the href element to point to the correct link and the collapse/expand functionality will then work for added items in the sequence. The patched version of mapping_accordion.pt is attached below. The 'idgoto' function should be put inside the deform JS file so it only gets loaded once instead of repeated for each mapping template but this dirty hack allows me to leave the installed deform library alone and just fix it with my own template (note - I had to change the extension from .pt to .txt to get it to attach - you will need to switch it back!). |
--- in/deform.js
+++ out/deform.js
@@ -61,6 +57,7 @@
var $htmlnode = $(html);
var $idnodes = $htmlnode.find('[id]');
var $namednodes = $htmlnode.find('[name]');
+ var $controls = $htmlnode.find('[aria-controls]');
var genid = deform.randomString(6);
var idmap = {};
@@ -87,6 +84,16 @@
$node.attr('name', newname);
});
+ // replace aria-controls and href a containing ```deformField`` like we do for ids
+
+ $controls.each(function(idx, node) {
+ var $node = $(node);
+ var oldid = $node.attr('aria-controls');
+ var newid = oldid.replace(fieldmatch, "deformField$1-" + genid);
+ $node.attr('aria-controls', newid);
+ $node.attr('href', "#" + newid);
+ });
+
$htmlnode.insertBefore(before);
$(deform.callbacks).each(function(num, item) {
|
I would accept a PR that resolves this issue with tests and a signed https://github.com/Pylons/deform/blob/master/CONTRIBUTORS.txt. Please let me know what I can do to help move this forward. |
Mixing accordion exemple with SequenceWidget and Select2Widget leads to some strange behaviour:
version: deform==2.0.4
Here some code to illustrate:
And a screen shot here:
The text was updated successfully, but these errors were encountered: