• Resolved peti73

    (@peti73)


    Hi,

    i was able to create a field with a shortcode from an external api using this method: Use shortcode as dynamic value

    But the value is not transferred to the next calculated field, maybe because the shortcode needs time to get its value, and the calculated field is displayed and calculated before it gets the data.

    Is there a method to delay the execution of the next fields? Or can i put a calculate button to execute or refresh the following fields?

    Thank You!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @peti73

    If you want to evaluate the equations manually by pressing a button:

    1. Untick the checkbox “Dynamically evaluate the equations associated with the calculated fields” in the “Form Settings” tab (https://resources.developers4web.com/cff/images/documentation/form-settings-tab.png)

    2. Insert a button field in the form, and tick the “Calculate” option as its type in the button settings.

    Best regards.

    Thread Starter peti73

    (@peti73)

    Hi,

    thank You for the answer, it works.

    Is it possible to achieve the same without a button? (ie. with some delay?)

    Plugin Author codepeople

    (@codepeople)

    Hello @peti73

    The plugin includes two operations you can call.

    If you have a custom code to fill a form field, and you want to evaluate the equations after evaluating your code, you can use the following piece of code:

    ENABLEEQUATIONS(jQuery('[id*="cp_calculatedfieldsf_pform_"]'));EVALEQUATIONS(jQuery('[id*="cp_calculatedfieldsf_pform_"]'));

    Best regards.

    Thread Starter peti73

    (@peti73)

    Where shall i write this code?

    One more question:
    i’ve created a multi-page form and have put that shortcode with the external api request to the second page. But it is executed right when i load the form.
    How can I make it to execute that shortcode only when i am on the second page?

    Thank You again!

    Plugin Author codepeople

    (@codepeople)

    Hello @peti73

    You should include the code snippet as part of the code you wrote to populate the field value (Right after filling out the field).

    Answering your second question. The code should be written in the “cff-gotopage” event:

    <script>
    fbuilderjQuery(document).one('cff-gotopage', function(){
    // Your code here
    });
    </script>

    Best regards.

    Thread Starter peti73

    (@peti73)

    Hi,

    unfortunately it doesn’t work (or i made some error):

    <script>
    fbuilderjQuery(document).one('cff-gotopage', function(){
    fbuilderjQuery(document).one('showHideDepEvent', function(){
    fbuilderjQuery.getJSON( 'https://api.metalpriceapi.com/v1/latest?api_key=[API_KEY]&base=USD&currencies=EUR,XAU,XAG', function(data){fbuilderjQuery('[id*="fieldname3_"]').val(1/data['rates']['XAU']);} );
    });
    });
    </script>

    I put this code on a html content field, tried on both pages, but no success.

    What am I doing wrong?

    Plugin Author codepeople

    (@codepeople)

    Hello @peti73

    You should use only one of the events:

    <script>
    fbuilderjQuery(document).one('cff-gotopage', function(){
        fbuilderjQuery.getJSON( 'https://api.metalpriceapi.com/v1/latest?api_key=[API_KEY]&base=USD&currencies=EUR,XAU,XAG', 
        function(data){
            fbuilderjQuery('[id*="fieldname3_"]').val(1/data['rates']['XAU']);
            ENABLEEQUATIONS(jQuery('[id*="cp_calculatedfieldsf_pform_"]'));
            EVALEQUATIONS(jQuery('[id*="cp_calculatedfieldsf_pform_"]'));
        });
    });
    </script>

    Best regards.

    Thread Starter peti73

    (@peti73)

    Superb! Thank You very much!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Delay for calculated fields?’ is closed to new replies.