Support » Plugin: Calculated Fields Form » set between value in Equation

  • Resolved Alwin

    (@wp-opti)


    I would like to set a Equation for a calculated field like this:

    “if the value of the calculated field is between 1 and 20”

    I came up with this:

    20<=fieldname2,1>=fieldname2,

    but it seems not to be working. How can i do this?

    Thank you,
    Alwin

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

    (@codepeople)

    Hello @wp-opti,

    Actually it is the same question that in your other tickets. So,I will try to describe all possible variants:

    Assuming there is an equation, where:

    If the value of the fieldname2 is lesser than 1 the equation should return the number 10, if the value is between 1 and 20 (including both), the equation’s result should be 100, and finally if the value is greater than 20 the result is 100.

    Note that it is a hypothetical case, only to describe the process.

    There are multiple alternatives:

    – Nesting multiple “IF” operations:

    
    IF(fieldname2<1,10,IF(AND(1<=fieldname2,fieldname2<=20), 100, 1000))
    

    – Nesting multiple ternary operators of javascript:

    
    (fieldname2<1) ? 10 : ((AND(1<=fieldname2,fieldname2<=20)) ? 100 : 1000)
    

    – Using the function structure and the conditional statement “if” of javascript (javascript is a case sensitive language, do not confuse the conditional statement “if” in javascript with the operation “IF” in the plugin):

    
    (function(){
    if(fieldname2<1) return 10;
    if(1<= fieldname2 && fieldname2 <= 20) return 100;
    return 1000;
    })()
    

    and that’s all.
    Best regards.

    Thread Starter Alwin

    (@wp-opti)

    This is where I have a problem with:

    IF(AND(20<=fieldname2,20<=fieldname6,20<=fieldname41,20<=fieldname42,
    PREC(MAX(27.84,fieldname40*0.46+26.00),2), ‘Warning text’)

    So if the number of the fieldname2,fieldname6 or fieldname41 is less then 20 then the warning text should be displayed.

    But the problem is that the fields2, 6 and 4 are set up with a Predefined Value of 0 (zero) which has to stay that way.

    So to avoid (get around) this Predefined Value of 0 I thought that instead of this:
    20<=fieldname2

    I would set ip up as “between 1 and 20”.

    But something like “1>=fieldname2,20<=fieldname2” is not working. So is there antoher way to do this?

    1>OR<20=fieldname2 or something like that?

    By the way: I already asked for info about some custom coding too and I will definitely use that service! But it would be great if I could solve this issue too today 🙂

    Plugin Author codepeople

    (@codepeople)

    Hello @wp-opti,

    Please, I need you read my tickets, the parentheses are wrong in your equation, you are not closing the “AND” operation.

    Furthermore, there is something wrong with your project’s description, if you need all fields be greater than or equal to 20, and the default values of fieldname2, fieldname6, fieldname41, and fieldname42 are zero, it is normal that the equation’s result be the warning text in the equation until the user enter all fields values:

    
    IF(AND(20<=fieldname2,20<=fieldname6,20<=fieldname41,20<=fieldname42),
    PREC(MAX(27.84,fieldname40*0.46+26.00),2), 'Warning text')
    

    A different implementation would be a patch.

    My recommendation would be disable the dynamic evaluation of the equations, and include a calculate button the user should press after entering the input fields to see the equations results:

    1. Go to the “Form Settings” tab (https://cff.dwbooster.com/images/documentation/form-settings-tab.png) and untick the checkbox: “Eval dynamically the equations associated to the calculated fields”

    2. Insert a button field in the form, and select as the button type (it is an attribute in the button’s settings) the “Calculate” option.

    Configuring the form in this way the user will see the warning text if really he has pressed the calculate button after entering invalid values in the input fields.

    Best regards.

    Thread Starter Alwin

    (@wp-opti)

    Thank you!

    Could it be that I can do it like this:
    IF(AND(>1,<20=fieldname2,

    to set a “between” number between 1 and 20?

    Plugin Author codepeople

    (@codepeople)

    Hello @wp-opti,

    I really need you read my tickets or won’t be possible for you to learn how the conditional statements and operations works. This question has been answered in different tickets, even I’ve described all possible variants to use.

    Please, read again my first ticket in this thread, I’ve described how to check if the value of a field is in a range:

    IF(AND(1<=fieldname2,fieldname2<=20), 100, 1000)

    It should be read literally, it is very straightforward:

    If the value of the fieldname2 is greater than or equal to 1 “and” the value of fieldname2 is lesser than or equal to 20 (the value is in the range) then, the result is 100, in other cases (if the value is lesser than 1 or greater than 20) the result of the equation is 1000

    Best regards.

    • This reply was modified 5 years, 8 months ago by codepeople.
    Thread Starter Alwin

    (@wp-opti)

    I am sorry, but this is the first time I am doing stuff like this and I find it very difficult…

    I appreciate your help very much.. 🙂

    Yoer example: IF(AND(1<=fieldname2,fieldname2<=20), 100, 1000)

    When the value is between 1 and 20 I don’t want the result to be 100 but I want to display a warning text

    In other cases, when the value is greater then 20, I want to display the result of:
    PREC(MAX(27.84,fieldname40*0.46+26.00),2)

    Can you help me with that (please…)?

    Plugin Author codepeople

    (@codepeople)

    Hello @wp-opti,

    You simply should replace the numbers by the text or the operations:

    
    IF(AND(1<=fieldname2,fieldname2<=20), 'warning text', PREC(MAX(27.84,fieldname40*0.46+26.00),2))
    

    I’m sorry, but I cannot continue implementing your project through the support forum. I’ve gave you all the tools and explanations to create the formulas, but if you need that I implement your project, you should request a custom coding service:

    https://cff.dwbooster.com/customization

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘set between value in Equation’ is closed to new replies.