• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Server 500 Error with Calc Watch Element

Status
Not open for further replies.

fudge4u

Member
I am trying to create a Cascading Dropdown Menu, and would like to use a calc element as the watch element. But every time I set a calc element to be the watch element, I get the 500 Internal Server Error.

Is it possible, or is there a workaround to being able to create this dropdown menu?

Using the latest Joomla! code and the latest GitHub update.
 
Hmmm, there seems to be an infinite recursion. The CDD is calling a function in the calc code, which calls the same function back from the CDD, which calls the function back from the calc, etc.

I'm not entirely sure this is fixable. So the answer may be "no, you can't use a calc as the watched element for a CDD".

I'll take another look at the code, see if I can find a fix.

-- hugh
 
That would be great if there is a fix for that. In the mean time, is there a way that the calc element can assign the calculated value to a field element, which I can then use as the watch element?
 
You can use a form PHP plugin, running 'onBeforeProcess' to assign values to filed elements, instead of using a calc.

So you can do pretty much the same code you have in your calc, but instead of returning it, do ...

Code:
// your code goes here to set $result
$formModel->updateFormData('yourtable___yourelement', $result, true);

If you are using inline code (rather than a included file) you can use element placeholders in your code, like {yourtable___whatever}. Or you can access the formData array, like $formModel->formData['yourtable___whatever'].

You can (probably) do this instead of, rather than as well as, a calc. The only situation this might not be true in is if your calc values can be affected outside of the form submission process, and you have "Calc on save only" set to No, such that they calc on list load. For example if you are displaying some time based value relative to "now", etc.

-- hugh
 
Still trying to make this work. My calc value changes depending on the selection of a CCD item on the form, so the calc would have to change the field element every time a different selection is made on the CCD.

Just wondering if you discovered anything about the infinite recursion which is triggering the 500 error. That would be the easiest fix for me - probably not for you, though!

I don't want to take up your time trying to help me with my code in the Community Forum.
 
Hmmm. You might be able to do it with some JS in the calc response itself. It's not documented, but your calc can return a <script>your JS goes here</script> in the response (I think it has to be at the end of the returned string), which will get evaluated, and stripped from the displayed value. I added it a while back for someone using Plotalot, so we could trigger a rebuild of the Plotalot graph after changing values.

So technically you could add something like ...

Code:
<script>Fabrik.getBlock('form_X').formElements.get('yourtable_yourfield').update(r);

... to update your field element with the same value the calc got (which will be in the r var).

You might also have to fire a change event on it as well, to get the CDD to notice the change.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top