Just trying to get some attention to this problem - as no one has responded.
To clarify this a bit. 3 elements are involved.
- A calc element
- A databasejoin element (multiselect checkboxes)
- A cascadingdropdown element (multiselect checkboxes - with the datbasejoin element as the 'watch' element)
The calc element references both the databasejoin and cascading dropdown elements.
When the form first loads, the calc element will get updated from any changes to the cascading dropdown element just fine.
And, when the form first loads, the calc element will get updated from changes made to the databasejoin (the CCD watch element) just fine.
BUT once a selection is changed in the DBJ element, then the CCD element no longer triggers the Ajax for the calc element.
In other words, it appears that the cascading dropdown is removed from the 'watch' options of the calc element once the watch element of the cascading dropdown has been changed.
It seems like, in one or both of those Ajax calls (from the calc and/or CCD), there needs to be some code added - to refresh all 3 of those elements so that they all work like they do/did when the form was initially displayed.
This is an important form to my project, as the calc element is used to display a 'Shopping Cart' for the PayPal form plugin. I have been fighting with this for a week and am anxious to get the issue resolved. (Or know that I'll need to come up with another method if this issue cannot be easilly fixed.)
And of note to Hugh (so you don't think I've just been sitting on my hands waiting for someone to fix this)..
I have tried for days to find/fix the problem. But I am not all that versed in javascript (especially these 'mini' files used).
A few things I would like to note from my debugging thus far...
The calc-min.js seems to have a typo - and greatly differs from the calc.js (non-minfied) code.
e.g.
Code:
attachedToForm:function(){if(this.options.ajax){{var a;this.form}
Shouldn't that be
Code:
attachedToForm:function(){if(this.options.ajax){{var a=this.form}
???
Also, in that calc-min.js I added some code so I could see the value of 'this.options.observe' in the console.log - and discovered that there were duplicates in the 'watch' options.
I could also see from that console.log that any OR ('||') condition that was used in the placeholders of the calc element was not being removed either. And there would sometimes be empty an string in the 'this.options.observe' array.
Assuming that this would cause some code to get run multiple times (and/or suspecting it was part of the bug), I set out to fix that.
SO.... Upon examining the code in the function elementJavascript() in calc.php, I saw what was causing those things to happen and made these changes to fix it -
- The array_unique() function was being called BEFORE changes to remove the '_raw' part from the element name - that needed to be done after.
- The function to remove '_raw' was not working/correct - so I just added that to the function that removed the '{' and '}'
- I added a function to remove any OR condition that was part of the element placeholders ('||xxxx')
- I moved the array_unique function to the bottom - after 1, 2, & 3
- I then removed any empty strings from that array - as the final $obs to pass in the Ajax call.
So, I have included below an updated version of the elementJavascript function (with old lines left intact, and with my comments) in calc.php...
PHP:
public function elementJavascript($repeatCounter)
{
$id = $this->getHTMLId($repeatCounter);
$opts = $this->getElementJSOptions($repeatCounter);
$params = $this->getParams();
$calc = $params->get('calc_calculation');
$obs = preg_replace('#\s#', '', $params->get('calc_ajax_observe'));
$obs = explode(',', $obs);
if (preg_match_all("/{[^}\s]+}/i", $calc, $matches) !== 0)
{
$matches = $matches[0];
$obs = array_merge($obs, $matches);
}
// Need to move this to after removing '_raw' and '||xxx'
// $obs = array_unique($obs);
foreach ($obs as &$m)
{
// $m = str_replace(array('{', '}'), '', $m);
// just include '_raw' here
$m = str_replace(array('{', '}', '_raw'), '', $m);
// $$$ hugh - we need to knock any _raw off, so JS can match actual element ID
// this wasn't working - see above
// $m = preg_replace('#_raw$#', '', $m);
// what about removing any OR ('||') in placeholder?
$m = (strpos($m,'||')) ? str_replace(substr($m,strpos($m,'||')), '', $m):$m;
}
// apply array_unique function last
$obs = array_unique($obs);
// then remove any blank strings
$obs = array_filter($obs);
$opts->ajax = $params->get('calc_ajax', 0) == 0 ? false : true;
$opts->observe = array_values($obs);
$opts->calcOnLoad = (bool) $params->get('calc_on_load', false);
$opts->id = $this->id;
return array('FbCalc', $id, $opts);
}
Please don't scold me for not doing this myself, but I really have little time in my day for anything 'extra' anymore. And I guess I'm just a prime example of the clich? - "You can't teach an old dog new tricks."