• Resolved blue

    (@life2)


    Hi, the form has a dropdown field and several currency fields. I want to show different currency fields depending on the selection in the dropdown field. How can I do this?

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

    (@codepeople)

    Hello @life2

    You can define dependencies between the choices in the dropdown fields and the corresponding currency fields. Please, read the following post in the plugin’s blog:

    https://cff.dwbooster.com/blog/2020/03/01/dependencies/

    Best regards.

    • This reply was modified 3 years, 7 months ago by codepeople.
    Thread Starter blue

    (@life2)

    Thanks, that was helpful. Is it also possible to use a different equation in the calculated field depending on the dropdown field selection?

    • This reply was modified 3 years, 7 months ago by blue.
    Plugin Author codepeople

    (@codepeople)

    Hello @life2

    Yes, of course. You can use conditional statements as part of the equation. I’ll try to describe the process with a hypothetical example.

    Assuming you have the dropdown field: fieldname1 with three choices whose values are: A, B, and C, and you want the equation’s result to be:

    fieldname2+12 if the choice with “A” value is selected.

    fieldname2+30 if the choice with “B” value is selected.

    And fieldname2+54 if the choice with “C” value is selected.

    The fields’ names are values are hypothetical, only to describe the process.

    Insert a calculated field in the form with the equation:

    
    (function(){
    if(fieldname1 == "A") return fieldname2+12;
    if(fieldname1 == "B") return fieldname2+30;
    if(fieldname1 == "C") return fieldname2+54;
    })()
    

    And that’s all.

    Best regards.

    Thread Starter blue

    (@life2)

    Thanks, one more question: I want to make sure that none of the fields are empty for the calculation to be performed (the calculation shows zero after filling some fields). What should I add inside the if statement to fix this?

    Plugin Author codepeople

    (@codepeople)

    Hello @life2

    Yes, that is. You can include conditional statements in the equations to evaluate the mathematical operations based on some conditions.

    Continuing with the previous example. If you want to return the mathematical result only if both fields, fieldname1, and fieldname2 were populated, you can edit the equation as follows:

    (function(){
        if(AND(fieldname1, fieldname2))
        {
            if(fieldname1 == "A") return fieldname2+12;
            if(fieldname1 == "B") return fieldname2+30;
            if(fieldname1 == "C") return fieldname2+54;
        }
        return '';
    })()

    Best regards.

    Thread Starter blue

    (@life2)

    Thanks, but the fields for each drop-down selection are different. So, the code you provided doesn’t work for all of them. How should I modify it?

    Plugin Author codepeople

    (@codepeople)

    Hello @life2

    The code I sent you is only an example of the use of conditional statements. You should take the idea from it and implement your project. However, keep in mind the value of dependent fields is zero when they are disabled.

    For example, if you have three dependent fields, their sum would be the value of the active field.

    Best regards.

    Thread Starter blue

    (@life2)

    Okay, I think you misunderstood what I meant. I understand this is just an example. To illustrate my point, here is an example (based on the one you provided);

    If fieldname1 (dropdown field) is ‘A’, the fields that are displayed are fieldname2 and fieldname3.

    If fieldname1 (dropdown field) is ‘B’, the fields that are displayed are fieldname4 and fieldname5.

    If fieldname1 (dropdown field) is ‘C’, the fields that are displayed are fieldname6 and fieldname7.

    The following code doesn’t work properly as only some of the fields will be populated for each dropdown selection (I will probably need to divide the fields in separate if-statements for each dropdown selection):

    (function(){
        if(AND(fieldname2, fieldname3, fieldname4, fieldname5, fieldname6, fieldname7))
        {
            if(fieldname1 == "A") return fieldname2+12;
            if(fieldname1 == "B") return fieldname2+30;
            if(fieldname1 == "C") return fieldname2+54;
        }
        return '';
    })()
    Plugin Author codepeople

    (@codepeople)

    Hello @life2

    Your equation does not work because the values of disabled fields are zero, in whose case the AND operation returns false.

    Following with your hypothetical example, you should use the “AND” operation per pair of fields, and an “OR” operation for pairs, as follows:

    (function(){
        if(OR(AND(fieldname2, fieldname3), AND(fieldname4, fieldname5), AND(fieldname6, fieldname7)))
        {
            if(fieldname1 == "A") return fieldname2+12;
            if(fieldname1 == "B") return fieldname2+30;
            if(fieldname1 == "C") return fieldname2+54;
        }
        return '';
    })()

    Best regards.

    Thread Starter blue

    (@life2)

    That’s exactly what I needed as everything is working properly now. Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Showing different fields based on a field selection’ is closed to new replies.