6 replies [Last post]
inkovation's picture
Offline
Joined: 06/15/2010
Juice: 52
Was this information Helpful?

I have page content that changes dynamically when attributes are selected in a pulldown (not radiobutton) with the DOM change happening via a javascript.

onchange of the selects, the page content updates appropriately.

Moments later the content reverts to it's starting state, I believe because uc_aac is also running code onchange of the same selects.

How can I exclude the updated page content, referenced by particular id's, from the uc_aac "sweep through" at

      // Replace HTML elements with new values.
      var node = $('#node-' + data.nid);
      for (var i in data.replacements) {
        var replacement = $(data.replacements[i]);
        $(node).find('.' + i).after(replacement).remove();
      }

If, in fact, this is what is causing my changes to get wiped back off the page?

Thanks in advance for your thoughts,
Pat

inkovation's picture
Offline
Joined: 06/15/2010
Juice: 52
solved!

I was able to use Drupal.attachBehavior with the help of

http://www.jaypan.com/blog/calling-function-after-ahah-event-drupal-6

and get my javascript to run when the ajax returned the new price calculation.

The site is working as needed.

(See www.midweststeelsupply.com/store/castAluminumPlate for example to see this in action)

When the various options are selected via select fields, the appropriate length or width dimensions are updated in the text field Length In Inches (or Width In Inches) with feet multiplied by 12, and fractional inch lengths converted to their decimal equivalent. So someone selecting "3" in the feet select, "6" in the inch select, and "1/2" in the inch fraction select will see the Length in Inches field update to 36", then 38" then 38.5" at each selection.

eagelke's picture
Offline
Joined: 02/17/2011
Juice: 7
Re: uc_aac conflicts with dynamic javascript

I'm not a good coder, but i managed to fix this issue.
I added a line in
sites/all/modules/uc_dynamicproductpages/uc_dynamicproductpages.js

making it

// $Id: uc_dynamicproductpages.js,v 1.1 2010/09/25 19:58:47 aidan Exp $

Drupal.behaviors.uc_dynamicproductpages = function(context) {

  $('.add-to-cart .attributes select', context).change(function(event) {   
    var optionNumber = $(this).val();
    var attribute    = $(this).parents('.attribute');
   
    attribute.find('.dynamic-product-attribute').hide();
    attribute.find('.attribute-option-' + optionNumber).fadeIn();
setTimeout(100);
  });
}

I guess the dynamic productpages just had to wait a little to first let uc_aac do it's work.

Works fine for me...

sundancenaturalist's picture
Offline
Joined: 07/13/2011
Juice: 7
Re: Re: uc_aac conflicts with dynamic javascript

I'm having the same problem described above. I tried adding the setTimeout (100); as suggested by eagelke. Now dynamic product pages is working normally (no longer being wiped clean by uc_aac), but the prices are no longer being adjusted. Basically behaves as though uc_aac was not enabled. Changing the setTimeout value does not seem to have any visible effect on the timing of the dynamic product pages when different attributes are selected. Are there any other suggestions for how to make dynamic productpages do its stuff after uc_aac?

inkovation's picture
Offline
Joined: 06/15/2010
Juice: 52
Re: Re: Re: uc_aac conflicts with dynamic javascript

In my case my needs were met with the following:

Drupal.behaviors.midwest = function()
{
$(document).ajaxComplete(function()
{

getTotals();
});

}

where the function I needed to run after the uc-aac return was "getTotals()" in a custom module named "midwest".

This code caused getTotals to run again after the ajax return.

Hope it helps!

sundancenaturalist's picture
Offline
Joined: 07/13/2011
Juice: 7
Re: Re: Re: Re: uc_aac conflicts with dynamic javascript

Thanks for the quick reply!
Unfortunately I'm unsure of how to do this. Sorry if this is supposed to be obvious, but could you be more explicit as to which files I need to edit or create?

inkovation's picture
Offline
Joined: 06/15/2010
Juice: 52
Re: Re: Re: Re: Re: uc_aac conflicts with dynamic javascript

Actually I was mistaken in my description above.

After the module (named midwest, in my case) returns values, and wipes out the changes my javascript function had made,

the code I showed above will cause a javascript function (named "getTotals()" for me) to run again.

If you can determine the what module is triggering your issue (using firebug:console may help, if you can)

and what function you need to rerun (firebug:script)

Your solution may be as simple as modifying the code I used by inserting your module name and function name.