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?)
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!
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¤cies=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?
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¤cies=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!