• Resolved lmobile

    (@lmobile)


    Dear support

    may you could help me with this problem:

    we have a calculation which shows different results depending on a percentage value. In the calculated fields form 4 fields are added, depending on the percentage result of the field the user is getting different answers.

    the rules are simple and work with the automatic rules within the “define dependencies” As example:

    If value is – is equal to 80 – If rule is valid show: fieldname17 + fieldname20

    This works until this fine. But we got the problem that the field should be another depending on the answer of the fields. As example –

    If value is – is equal to 80 and fieldnameX is (answered yes or value of the answer 20) than use fieldnameXX + fieldnameXXX or If value is – is equal to 80 and fieldnameX is (answered yes or value of the answer 20) and fieldnameXX (answered yes or value of the answer 15) than use fieldnameXXX

    Hope this is understandable…..Is it possible to achieve something like that? We are using the platinum version of the plugin.

    Thanks for your support Marc

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

    (@codepeople)

    Hello @lmobile

    Your problem’s description is a bit confusing. But, that seems you are describing an equation with conditional statements and not exactly dependencies.

    For example, assuming you have the fieldname1 whose values can be 80 or 90, and a fieldname2 with possible values: “Yes” or “No”. And based on the fields’ values, you want to return:

    fieldname3+fieldname4
    fieldname3+fieldname5
    fieldname3+fieldname6

    or

    fieldname3+fieldname7

    The equation can be implemented as follows:

    (function(){
    if(AND(fieldname1 == 80, fieldname2 == 'Yes') return fieldname3+fieldname4;
    if(AND(fieldname1 == 80, fieldname2 == 'No') return fieldname3+fieldname5;
    if(AND(fieldname1 == 90, fieldname2 == 'Yes') return fieldname3+fieldname6;
    if(AND(fieldname1 == 90, fieldname2 == 'No') return fieldname3+fieldname7;
    })()

    Or nesting the conditional statement (both equations return the same result):

    (function(){
        if(AND(fieldname1 == 80)
        {
            if(fieldname2 == 'Yes') return fieldname3+fieldname4;
            return fieldname3+fieldname5;
        }
        else
        {
            if(fieldname2 == 'Yes') return fieldname3+fieldname6;
            return fieldname3+fieldname7;
        }
    })()

    Best regards.

    Thread Starter lmobile

    (@lmobile)

    Dear support

    thanks. Hope I understand it the right way ?? Will try. But to be sure – how the used answer fields must be formatted? For the answer I used HTML fields. Does that work? Also
    where to go with the equation? In another calculated field?

    Thanks for your help Marc

    Plugin Author codepeople

    (@codepeople)

    Hello @lmobile

    There is not a unique answer to your question. The calculated fields use input tags, and the input tags do not render HTML. So, if you need to format the answer in some specific way, like:

    <p>Hello <b>User name field</b>, the result is <span style="color:red;">equation result here</span></p>

    You should use the calculated field as an auxiliary field to generate the paragraph but display it in another field.

    For example, you can insert an “HTML Content” field with a div tag as its content where display the equation’s result, like:

    <div class="result-here"></div>

    And the equation could be implemented as follows:

    jQuery('.result-here').html('<p>Hello <b>'+fieldname8+'</b>, the result is <span style="color:red;">'+fieldname9+'</span></p>');

    Since the calculated field is used as an auxiliary field, you can hide it by ticking a checkbox in its settings.

    Note I’m sending you some examples, but should adapt them to your project. You can implement the process with multiple calculated fields or only one field.

    For example, merging this equation with the equation in the previous entry:

    jQuery('.result-here').html('<p>Hello <b>'+fieldname8+'</b>, the result is <span style="color:red;">'+(function(){
        if(AND(fieldname1 == 80)
        {
            if(fieldname2 == 'Yes') return fieldname3+fieldname4;
            return fieldname3+fieldname5;
        }
        else
        {
            if(fieldname2 == 'Yes') return fieldname3+fieldname6;
            return fieldname3+fieldname7;
        }
    })()+'</span></p>');

    As you can see, the equation can be as simple or complex as you need.

    Best regards.

    Thread Starter lmobile

    (@lmobile)

    Deear support

    me again ?? Some similar code I found in the documentation comes close to what I want to achieve. Tried to figure out to expand this to my needs, but totally failed….

    IF(AND(fieldname2 == 20, 80 == fieldname12), 1, 0)

    This code I am using with dependies to the value 1 and 0.

    But I have three different fields to show or hide depending on these values:

    1. fieldname2 == 20 and fieldname12 == 80 If rule is valid show fieldname22
    2. fieldname2 == 20 and fieldname12 <= 80 If rule is valid show fieldname21
    2. fieldname2 == 0 If rule is valid show fieldname19

    Is it possible to include this 3 options in a code like that above?

    Thanks a lot for you help Marc

    • This reply was modified 3 years, 4 months ago by lmobile.
    Plugin Author codepeople

    (@codepeople)

    Hello @lmobile

    Yes, of course, and the equation would be similar to the previous ones:

    
    (function(){
    if(fieldname2 == 20 && fieldname12 == 80) return 1;
    if(fieldname2 == 20 && fieldname12 <= 80) return 2;
    if(fieldname2 == 0) return 3;
    })()
    

    Now, you can define the dependencies in the settings of the calculated field:

    If the value is equal to 1, activate the fieldname22 field.
    If the value is equal to 2, activate the fieldname21 field.
    If the value is equal to 3, activate the fieldname19 field.

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to add different dependies rules to calculated field’ is closed to new replies.