1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Server 500 Error with Calc Watch Element

Discussion in 'Community' started by fudge4u, Sep 12, 2018.

Thread Status:
Not open for further replies.
  1. fudge4u

    fudge4u Member

    Level: Community
    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.
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    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
     
  3. fudge4u

    fudge4u Member

    Level: Community
    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?
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    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 (Text):

    // 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
     
  5. fudge4u

    fudge4u Member

    Level: Community
    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.
     
  6. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    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 (Text):

    <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
     
  7. fudge4u

    fudge4u Member

    Level: Community
    Thanks for your help. I was able to get my form working.
     
Thread Status:
Not open for further replies.

Share This Page