Calc works in PHP/Submit but not in Ajax

Duke3D

Member
I have a calc element that works correctly on Save with either a button group or dropdowns.

Two issues:
1) If source element is displayed as button group, Ajax calc is not triggered regardless of whether element or element_raw is in the watchlist for the calc itself.
This is reported in https://github.com/Fabrik/fabrik/issues/1224 as being solved/closed, but apparently I do not know how to correctly trigger it. Is some JS needed to tickle the watcher?

2) If source is changed to a dropdown, the Ajax calc returns "undefined," but the total is still correct on save whether element or element_raw is used in the calc.

The dropdown values/radio buttons are integers (scores of 1-9)
I am using the syntax suggested in the popup:
<code>return (int)'{lpc_evaluations___score1}' + '{lpc_evaluations___score2}';</code>
What should I try next to get same result from Ajax as calc?
I tried wrapping with intval() in case the issue is selecting the radiobuttons plugin is force-casting the field as SQL type TEXT.
<code>return (int)intval('{lpc_evaluations___score1}') + intval('{lpc_evaluations___score2}');</code>

But no joy.
I'm guessing this is because the Ajax execution of this PHP is more sensitive to data type. Any other ideas?
 
Last edited:
Troester -
Thanks for pointing me to the PR posted by Rob this morning. I just applied the new radiobutton.php and as radiobutton-min.js but no joy.
No harm done by the code change, but calc is still not triggered from a radiobutton buttongroup.

Still baffled about why a calc on dropdowns comes back 'undefined' in page but works on submit.
 
The new code is in radiobutton.js only (I don't have a tool to minify).
If you want to patch manually you can enable "Debug JS" in Fabrik Debug options (this will run radiobutton.js) or copy radiobutton.js to radiobuttin-min.js or minify yourself.

It's working on my site with this code.
Did you clear Joomla and browser cache to get rid of old JS?
 
I had copied the js code into radiobutton-min.js and checked in the browser - the correct version is loading.
Tried with and without a watchlist, adding up either all regular and all raw elements. Not sure where to see if click event has been modifed in dev tools. I'm sure there is a way to see it. Can PM a login if you want to view.
 
Double-checked and the new js is loaded.
I went to look at attached events. Not sure how to interpretas this is a tool I am unfamiliar with. Explored one of the button groups for click events and found attached code that was nested what seems like an excessive number of times. - see screenprint.
Fabrik-Front.png
 
I saw in the code mention of conflicts with Template.js included with Protostar, which is the template I am using to minimize conflicts. I reviewed the code and all it seems to be doing is changing classes via jQuery that affect visual display of buttons but not their behavior/event triggers.
 
I will try again.

Any thoughts on the "undefined" returned by Ajax on a calc based on dropdowns that works just fine on Save and on Load List? Simple addition using the syntax in the tooltip. Setting to Dropdown element forces the field to be changed to Text.

<code>return (int)'{lpc_evaluations___score1}' + '{lpc_evaluations___score2}';</code>

Tried adding intval in case the issue was needing to convert string to number but no joy.

<code>return (int)intval('{lpc_evaluations___score1}') + intval('{lpc_evaluations___score2}');</code>

http://screencast.com/t/bfFbPecYJObZ
 
Last edited:
Well, the good news is that the radio button is firing the calculation.
The bad news is that it is returning "undefined" while the calc on Save works.

<code>return (int)'{lpc_evaluations___score1}';</code>
or
<code>return (int)intval('{lpc_evaluations___score1}');</code>
Even the simplest syntax returns "undefined".
 
No, I don't.

I suddenly had 403's show up over the weekend due to Rochen changing the ModSecurity rules but supposedly the site is now whilelisted. I see nothing in the errorlogs. Makes me wonder if the AJAX activity falls in a different Access category than the one for Form Edit. If the AJAX call is considered Public instead of Registered, that would be a trigger.

This gives me a clue of things to look for and try on the elements that are being read and added together.

For my troubleshooting information, how were you able to see this? What tool - tab - view shows the 403 response?
 
Last edited:
Debug it with either Developer Tools in Chrome, or FireBug in Firefox. Here's Chrome ... dev tools is on the menu, or ctrl-shift-i ...

http://screencast.com/t/LUTGnU2BNL

And note that the URL it is trying to post for the calc is relative to the full URL of this page, rather than relative to your site root, which is probably why it's failing. And the reason for that is, something is setting the base href to that.

-- hugh
 
Hmmm, looking at my test sites, the base href is being set to the full page URL on those as well. So it should work. But something in your setup is rejecting it.

What are your SEF setting in J!?

Are you using an htaccess?

-- hugh
 
Makes me wonder if the AJAX activity falls in a different Access category than the one for Form Edit. If the AJAX call is considered Public instead of Registered, that would be a trigger.

Nope, AJAX calls use the same session, and load the J! framework just like regular page loads, so all the access controls should be same-same.

This isn't an issue I've ever seen before, so it's something to do with your setup, or Rochen's mod_security.

-- hugh
 
Just FYI I tried accessing the same page with a non-SEF'ed link, just index.php?option=com_fabrik&view=form&formid=7&rowid=2993, and I get the same issue except it's "You don't have permission to access /index.php".

So I'm pretty sure it's probably an issue with mod_security, or something similar.

-- hugh
 
Apologies for the delayed reply - got swamped due to an event that kept me offline.

Thank you for helping to track it down and explaining the inner workings. Chasing it now.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top