• Resolved freezer33

    (@freezer33)


    Hi,

    I’m trying to work out how to show/hide a field based on a conditions applied the total sum field.

    I want to show/hide a field based on the “>= 4” part of the equation below. Can you help?

    var discount = 1;
    var result = fieldname31+fieldname16+fieldname54+fieldname58;

    if(fieldname5+fieldname36+fieldname53+fieldname57 >= 4) discount = 0.95;
    return result*discount+fieldname27+fieldname28;

    })(),2)

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

    (@codepeople)

    Hello @freezer33,

    The easier way would be defining dependencies in the calculated fields (you can insert a calculated field only for controlling the dependencies). More information in the following link:

    https://cff.dwbooster.com/documentation#dependencies

    Best regards.

    Thread Starter freezer33

    (@freezer33)

    Hi, maybe i wasn’t clear. I’m already using dependencies to show/hide fields, this isn’t my issue right now.

    The ‘caluclated field’ doesn’t have an option for ‘if fieldname’ it only has an option for ‘if value’. Therefore I am assuming this needs to be created within the script element to achieve what I am after, as it can’t be achieved otherwise as far as I can tell. Thanks ??

    Plugin Author codepeople

    (@codepeople)

    Hello @freezer33,

    What do you mean with “if fieldname”?

    The dependencies works as a chain, for example, if the field B depends of result of the field A, and the field C depends of result in the field B. So, if the field A hides the field B the field C would be hidden too.

    Show/hide a field from the equation’s code is very simple, but does not mean you are defining a dependency. For example, select a field in the form and assign to it a custom class name, the class name you want, for example I will assign: my-field

    The class names are assigned to the fields through the “Add CSS Layout Keyword” attribute.

    If you want hide this field as part of the equation, you simply should include the piece of code below as part of the equation:

    
    jQuery('.my-field').hide();
    

    and for showing the field:

    
    jQuery('.my-field').show();
    

    Best regards.

    Thread Starter freezer33

    (@freezer33)

    Hi,

    If script added in the ‘Set equation’ box is thus. I’m trying to work out how to get fieldname42 to show only when the total number form all the fields selected are >=2. Thanks

    PREC((function(){

    var discount = 1;
    var result = fieldname31+fieldname16+fieldname54+fieldname58;

    if(fieldname5+fieldname36+fieldname53+fieldname57 >= 2) discount = 0.95;
    if(fieldname5+fieldname36+fieldname53+fieldname57 >= 4) discount = 0.90;
    if(fieldname5+fieldname36+fieldname53+fieldname57 >= 2) jQuery(‘fieldname42’).show();
    return result*discount+fieldname27+fieldname28;

    })(),2)

    Plugin Author codepeople

    (@codepeople)

    Hello @freezer33,

    I’m sorry, but you’ve not following my instructions. Furthermore, You don’t need to repeat the sum, because would be affecting the performance of your form. Please, follow the instructions below:

    1. Select the fieldname42 in your form, and enter the following text into the “Add CSS Layout Keyword” attribute: the-show-hide-field

    2. Now edit the equation as follows:

    
    (function(){
        var discount = 1, 
            tmp = fieldname5+fieldname36+fieldname53+fieldname57,
            result = fieldname31+fieldname16+fieldname54+fieldname58;
    
        if(2 <= tmp){
            discount = 0.95;
            jQuery('.the-show-hide-field').show(); 
        }
        else
        {
            jQuery('.the-show-hide-field').hide(); 
        }
    
        if(4 <= tmp ) discount = 0.90;
        return PREC(result*discount+fieldname27+fieldname28,2);
    })()
    

    I’m sorry, but the support service does not cover the implementation of users’ projects (forms or formulas). If you need additional support implementing your project, I can offer you a custom coding service from my private website:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter freezer33

    (@freezer33)

    Hi,

    Sorry, thought this would be simpler. I’ll contact you for paid custom support moving forward.

    Thanks for your help thus far.

    Thread Starter freezer33

    (@freezer33)

    That resolved my issue. Happy to pay for this fix so will be in contact shortly.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘hide/show field based on conditions in total sum field’ is closed to new replies.