Wrapper <div> repeated on AHAH request
wulff - January 29, 2009 - 13:25
| Project: | AHAH helper |
| Version: | 6.x-2.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Description
After an AHAH request, the wrapper <div> is rendered again. This seems unnecessary and results in the document having two <div>s with the same ID.
Steps to reproduce:
- Enable the ahah_helper_demo module.
- Go to '/ahah_helper_demo'.
- Change the dropdown from 'Private' to 'Company'.
The document now looks like this:
<form id="ahah-helper-demo-form" method="post" accept-charset="UTF-8" action="/ahah_helper_demo">
<div>
<div id="billing-info-wrapper">
<div>
<div class="messages error">Address field is required.</div>
<div id="billing-info-wrapper">
<fieldset>
...
</fieldset>
</div>
</div>
</div>
...
</div>
</form>Notice the two <div>s with the ID 'billing-info-wrapper'.
The attached patch removes the #prefix and #suffix from the AHAH form element before it is rendered. The result of the above steps with the patch applied is:
<form id="ahah-helper-demo-form" method="post" accept-charset="UTF-8" action="/ahah_helper_demo">
<div>
<div id="billing-info-wrapper">
<div>
<div class="messages error">Address field is required.</div>
<fieldset>
...
</fieldset>
</div>
</div>
...
</div>
</form>| Attachment | Size |
|---|---|
| ahah_helper.module.patch | 781 bytes |

#1
Thanks, I'll review this soon.
#2
It helped here +1 ;)
#3
#4
Just a warning. If you use the #prefix or #suffix to display content this patch will cause that content to disappear on ahah update.
#5
I don't think blindly removing prefix and suffix is the way to go. People use different ways to create divs which ahah then replaces. One thing that jumps out to me is if you don't use replace as a ahah method but rather append or after then removing suffix and prefix doesn't make sense. Unfortunately I don't have a solution how to solve this to please everyone.
#6
I agree that a one size fits all solution is rarely correct.
I think replace though is the most common usage. At least it has been for me.
My thought is that the form definition could? / should? tell ahah_helper what to do. So, for example, if we say strip #prefix and #suffix is the 'default' action then:
if (!$form['#keep_wrapper']){
unset($form_item['#prefix'], $form_item['#suffix']);
}
If we say keeping #prefix and #suffix is the 'default' action then:
if ($form['#strip_wrapper']){
unset($form_item['#prefix'], $form_item['#suffix']);
}
perhaps a configuration for the module is the right way to handle choosing from the above?