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:

  1. Enable the ahah_helper_demo module.
  2. Go to '/ahah_helper_demo'.
  3. 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>

AttachmentSize
ahah_helper.module.patch781 bytes

#1

Wim Leers - February 14, 2009 - 16:18
Version:6.x-1.0» 6.x-2.0

Thanks, I'll review this soon.

#2

zeropaper - February 18, 2009 - 17:45

It helped here +1 ;)

#3

antgiant - February 23, 2009 - 15:53
AttachmentSize
ahah_helper.module.patch 778 bytes

#4

antgiant - February 23, 2009 - 19:40

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

Rok Žlender - August 31, 2009 - 01:55
Status:needs review» needs work

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

jefkin - November 5, 2009 - 14:58

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?

 
 

Drupal is a registered trademark of Dries Buytaert.