I am seeing an extra div appearing on the teaser after I add something to my cart that is totally screwing up my theme. I seem to recall a discussion as to how to prevent an extra div from showing up but for the life of me I can't find it now (of course) does anyone have a clue as to how to correct this?

btw the div has no idea or additional classes but does have a style of display:block on it.

Comments

Christopher Riley’s picture

Issue summary: View changes

I found an old post that talks about it but so far haven't figured out a fix.

https://api.drupal.org/api/drupal/includes!ajax.inc/function/ajax_comman...

Christopher Riley’s picture

It appears that this is a lovely behavior of the main ajax.js to keep things nice and clean. For the time being in a custom template I have wrapped the whole template with a div that has a class of display:inline-block on it. Its not pretty and would love to hear if others have ideas or suggestions, but it works for now.

Thanks all.

subhojit777’s picture

@Chris The issue is with ajax_command_replace(). Will remove the extra newlines that comes from the template file, as suggested here: https://api.drupal.org/comment/32698#comment-32698. Will fix this issue soon. Thanks!

subhojit777’s picture

After some research I found that the solution mentioned here https://api.drupal.org/comment/32698#comment-32698 does indeed removes the div wrapper. But I am still getting a div wrapper with display: block. Might be some other issue.

Christopher Riley’s picture

I appreciate you looking into it and it too has me perplexed. I was hoping to find the issue and whip up a patch for you but I need to get a site launched. I'll hopefully have time to revisit it later and or someone else will see something to correct it.

Thanks again.

subhojit777’s picture

@Chris I looked into the issue for hours and was really confused. Everything is okay with the template that is shown through ajax_command_replace(), seems like ajax_command_replace() works like that only. Will try to figure out something soon, or will have to find some other way round. Apart from bug fixing I am also working on new features of this module. Will let you know if I find anything :) Thanks!

torgosPizza’s picture

subhojit777’s picture

Status: Active » Needs work
subhojit777’s picture

Title: Extra Div » Extra div after ajax updates
subhojit777’s picture

Assigned: Unassigned » subhojit777
Category: Support request » Bug report
joelpittet’s picture

Is this still happening after that fix mentioned in #7?

subhojit777’s picture

Yes. Infact I am working on this issue right, and I guess I will be able to fix this. Will come up with a patch in few days or by this coming weekend :)

joelpittet’s picture

Ok cool, let us know the Steps to Reproduce so we can manually test, gladly test it out:)

matsjacobsson’s picture

Hi,

For me it was adding more divs due to the fact that the ajax_command_replace uses the theme function from a template file (that I have added extra divs to).

To get this to work I wrapped the whole template file (dc-ajax-shopping-cart.tpl.php after the if($order && $quantity != 0): function) with the ajax-shopping-cart-wrapper div instead of having it wrapping just the products_list_html.

<?php $content = ''; ?>
<?php if($order && $quantity != 0): ?>
<div class="ajax-shopping-cart-wrapper">
....
  <div class="custom divs">
         <!-- here comes the list that needs to be updated -->
        <?php print $products_list_html; ?>

<div class="more custom divs">
....
</div><!-- closing ajax-shopping-cart-wrapper -->
<?php endif; ?>

To remove the extra <div style="display:block;"> I removed the new lines as suggested

$new_markup = str_replace(array("\r", "\n"), '', $ajax_shopping_cart_content);
$commands[] = ajax_command_replace('.ajax-shopping-cart-wrapper', $new_markup);

I also removed the div selector in: div.ajax-shopping-cart-wrapper that seamed to mess upp the markup. (When doing ajax_command_replace i also usually use id instead of class if that is possible, but classes should work to ofcourse..)

/Mats

  • subhojit777 committed 7c6e0b6 on 7.x-1.x
    Issue #2318385 by cmriley: Extra div after ajax updates
    
subhojit777’s picture

Status: Needs work » Fixed

The last commit will fix the issue. I am not using ajax_command_replace() anymore for replacing the cart content. I have introduced a new Ajax command dc_ajax_add_cart_command_html() that does the same thing as ajax_command_replace(), just it won't add an extra wrapper div with style display: block.

The code needs to be optimized, and automated tests needs to be written. I will carry them out in another issue.

subhojit777’s picture

Thanks @matsjacobsson for your suggestion. But using a separate Ajax command seems a cleaner approach here.

  • subhojit777 committed 7c6e0b6 on 7.x-2.x
    Issue #2318385 by cmriley: Extra div after ajax updates
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.