Support » Plugin: Calculated Fields Form » 3 calculators merge to 1

• Resolved Sportuojantys

(@needfeed)

Hello, I wanted to ask help about merging 3 calculator, which I made with CFF to 1 calculator with extra field, coz their functions are similar, I just can‘t create the merged formula so I wanted to ask a help.
In the new calculator I will add 1 more selection (let‘s call it ‘fieldnameX‘) which includes all 3 parameters below: (those parameters are: ‘gain’ weight; ‘lose’ weight; ‘remain’ same weight).
New field will be called: fieldnameX. This field will have variables: ‘gain’, ‘lose’, ‘remain’.
These 3 calculators and their formulas are:
1. Calculator for gaining weight (link: https://sportuojantys.lt/skaiciuokles/makroelementu-skaiciuokle-auginant-mase/)
PREC(fieldname3==’Vyras’?(fieldname4==’3-4 treniruotės’?42*fieldname2:52*fieldname2):(fieldname4==’5 ir daugiau treniruočių’?47*fieldname2:36*fieldname2))

2. Calculator for losing weight. (link: https://sportuojantys.lt/skaiciuokles/makroelementu-skaiciuokle-metant-svori/)
PREC(fieldname3==’Vyras’?(fieldname4==’3-4 treniruotės’?28*fieldname2:38*fieldname2):(fieldname4==’5 ir daugiau treniruočių’?35*fieldname2:25*fieldname2))

3. Calculator for remaining the same weight (link: https://sportuojantys.lt/skaiciuokles/makroelementu-skaiciuokle-palaikant-svori/)
PREC(fieldname3==’Vyras’?(fieldname4==’3-4 treniruotės’?33*fieldname2:42*fieldname2):(fieldname4==’5 ir daugiau treniruočių’?39*fieldname2:31*fieldname2))

I know that I need more of „((()))“ symbols in merged formula but I just can‘t figure it out, so maybe you can help me?

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

(@codepeople)

Hello @needfeed

You only need an additional field for goals and some conditional statements in the equation. For example, assuming you have the fieldname123 field in the form with the options:

gain weight
lose weight
remain the same weight

The equation to group all these case can be implemented as follows:

``````(function(){
if(fieldname123 == 'gain weight') return ROUND(fieldname3=='Vyras'?(fieldname4=='3-4 treniruotės'?42*fieldname2:52*fieldname2):(fieldname4=='5 ir daugiau treniruočių'?47*fieldname2:36*fieldname2));

if(fieldname123 == 'lose weight') return ROUND(fieldname3=='Vyras'?(fieldname4=='3-4 treniruotės'?28*fieldname2:38*fieldname2):(fieldname4=='5 ir daugiau treniruočių'?35*fieldname2:25*fieldname2));

if(fieldname123 == 'remain the same weight') return ROUND(fieldname3=='Vyras'?(fieldname4=='3-4 treniruotės'?33*fieldname2:42*fieldname2):(fieldname4=='5 ir daugiau treniruočių'?39*fieldname2:31*fieldname2));
})()``````

And that’s all.

Best regards.

(@needfeed)

CodePeople, thank you for such a fast response.
You have unique mindset, I’m glad that I recommended your CFF for all my friends because you deserve more attention, CFF is da best 😉
Take a look at merged calculator, thanks to you 🙂
https://sportuojantys.lt/skaiciuokles/makroelementu-skaiciuokle-metant-svori/

Plugin Author codepeople

(@codepeople)

Best regards.

(@needfeed)

Hey, codepeople, I wanted to ask 1 more function of a field:
is it possible, that fieldname111 would be hiden until I select option “gain weight” AND click CALCULATE? (if I select option “lose weight” AND click CALCULATE, this field shouldn’t show up)

Plugin Author codepeople

(@codepeople)

Hello @needfeed

Who is the fieldname111 field? Your form does not included a fieldname111.

Best regards.

(@needfeed)

Yeah, it was just example 🙂
I merged 4th calculator to our previous version. It it looks like this:
https://sportuojantys.lt/skaiciuokles/dienos-kaloriju-normos-skaiciuokle/
That 4th option in first field is little different than other 3, coz there are 2 more parameters: height and age, but that’s not the case 🙂

Full formula (for kcal only):

(function(){
if(fieldname9 == ‘auginti’) return ROUND(fieldname3==’Vyras’?(fieldname4==’3-4 treniruotės’?42*fieldname2:52*fieldname2):(fieldname4==’5 ir daugiau treniruočių’?47*fieldname2:36*fieldname2));

if(fieldname9 == ‘mesti’) return ROUND(fieldname3==’Vyras’?(fieldname4==’3-4 treniruotės’?28*fieldname2:38*fieldname2):(fieldname4==’5 ir daugiau treniruočių’?35*fieldname2:25*fieldname2));

if(fieldname9 == ‘laikyti’) return ROUND(fieldname3==’Vyras’?(fieldname4==’3-4 treniruotės’?33*fieldname2:42*fieldname2):(fieldname4==’5 ir daugiau treniruočių’?39*fieldname2:31*fieldname2));

if(fieldname9 == ‘isgyventi’) return ROUND(fieldname3==’Vyras’?(66+(13.75*fieldname2)+(5*fieldname10)-(6.76*fieldname12)):(655+(9.6*fieldname2)+(1.85*fieldname10)-(4.7*fieldname12)));

})()

My question: how to make fields below the CALCULATE button (those fields, where the answers is written), to appear ONLY AFTER clicking the CALCULATE button?
fieldname1 (kcal)
fieldname6 (proteins)
fieldname7 (carbs)
fieldname8 (fats)

Plugin Author codepeople

(@codepeople)

Hello @needfeed

1. Enter the class name: `hide` into the “Add CSS Layout Keywords” attributes of fields, fieldname1, fieldname6, fieldname7, and fieldname8.

2. Enter the following piece of code into the onlick event of the button:

`jQuery('#fbuilder .hide').removeClass('hide');`

And that’s all.
Best regards.

(@needfeed)

Thanks, you can click the link I have posted, to see the results.
Now those 4 field appearing like we needed, but there are 2 problems:
1. When you once click the CALCULATE button, and then change the first option (gain, remain, lose weight or basic weight), the results 4 fields aren’t disappearing and their numbers are remaining the same like it was with last calculation, until you click CALCULATE again.
2. When in the first option you select the 4th parameter (basic calories), in the results section, appear all 4 fields:
fieldname1 (kcal)
fieldname6 (proteins)
fieldname7 (carbs)
fieldname8 (fats)

But we only need fieldname1 (kcal).
Before your example, I tried to use “Dependencies” option where I set that fieldname6 (proteins), fieldname7 (carbs) and fieldname8 (fats) only show with selections Nr. 1, 2 and 3 in the first option, but I deactivated this option because it was not comfortable with your example with ‘hide’ function 🙂

Plugin Author codepeople

(@codepeople)

Hello @needfeed

That is not an issue. Your equations are evaluated when you press the “Calculate” button. If you change the entry fields, the results are not modified until you press the “Calculate” button again to reevaluate the equations.

Another thing is to hide the fields for results when you enter any value in the entry fields.

Note that it is not part of the plugin. This request is specific to your project and must be implemented as part of the form’s code.

You can insert an “HTML Content” field in the form with the piece of code:

``````
<script>
jQuery(document).on('change', '[id*="fieldname9_"],[id*="fieldname3_"],[id*="fieldname2_"],[id*="fieldname4_"]',function(){
});
</script>
``````