• Resolved dwaynne

    (@dwaynne)


    Hi, codepeople –

    Is it possible to display a field if its resulting value is zero or above? I’ve reviewed setting dependencies based on other fields (https://cff.dwbooster.com/blog/2020/03/01/dependencies/) but I am not quite sure how the rules would work in this scenario.

    Also (sorry) is there a way to preserve 2 decimal places in a result answer and round up? So $1,875.50 becomes $1,876.00?

    Thanks in advance.

    The page I need help with: [log in to see the link]

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

    (@codepeople)

    Hello @dwaynne

    Thank you so much for using our plugin.

    Yes, you can define the dependencies in the calculated field to display a second field if the equation’s results are >= 0

    In the settings of the calculated field, there is a section to define dependencies. Select the rule “if value is greater than or equal to”, enter the number 0 into the box, and select the dependent field from the fields list (https://resources.developers4web.com/cff/images/articles/dependencies/calculated-field-wizard.png).

    Regarding the number of decimal places, you decide this number by using the PREC operation as the outermost operation in the equation.

    PREC(X, Y) rounds the number X with Y decimal places.

    For example, assuming you have the equation fieldname1*fieldname2, but you want the result with two decimal places, you should edit the equation as PREC(fieldname1*fieldname2, 2)`

    Best regards.

    Thread Starter dwaynne

    (@dwaynne)

    Hi, @codepeople

    Thanks for that. Let me clarify the dependencies issue further. For this particular field, the dependency doesn’t reside with another field, but with the value the field itself produces. So if the field’s result is zero or greater it should be displayed, otherwise it is hidden.

    As for the rounding, I do have the PREC function applied, e.g.

    PREC((function () {
    return fieldname10*0.5;
    })(), 2);

    While this does preserve the 2 decimal places (e.g. a result of $1,875.50 is seen), is there a further/replacement method I can use to add to round up the results (e.g. make the $1,875.50 into $1,876.00)? Like a combo of ROUND and PREC?

    Thanks again.

    Plugin Author codepeople

    (@codepeople)

    Hello @dwaynne

    To answer both questions use the equation:

    
    (function(){
    var result = fieldname10*0.5;
    if(0 <= result) return PREC(CEIL(result), 2);
    return '';
    })()
    

    Best regards.

    Thread Starter dwaynne

    (@dwaynne)

    Thanks, @codepeople. The rounding up works, but the field still shows in scenarios where I have return ”; for example:

    PREC((function () {
    if (fieldname3=='Common Law' && fieldname6=='No mortgage financing') return '';
    if (fieldname2>0 && fieldname6=='No mortgage financing') return (fieldname8+fieldname9);
    })(), 2);
    Plugin Author codepeople

    (@codepeople)

    Hello @dwaynne

    If you want to hide the field, you can do the following, assign it a custom class name. Ex:

    my-custom-field

    The class names are assigned to the fields through their “Add CSS Layout Keywords” attributes.

    And then, edit your equation as follows:

    (function () {
        jQuery('.my-custom-field').addClass('hide-strong');
        if (fieldname3=='Common Law' && fieldname6=='No mortgage financing') return '';
        if (fieldname2>0 && fieldname6=='No mortgage financing')
        {
            jQuery('.my-custom-field').removeClass('hide-strong'); 
            return PREC(fieldname8+fieldname9, 2);
        }
    })()

    Best regards.

    Thread Starter dwaynne

    (@dwaynne)

    Thanks, @codepeople. And just be sure, to add the rounding feature you highlighted before, do I use

    return PREC(CEIL(fieldname8+fieldname9), 2);

    Plugin Author codepeople

    (@codepeople)

    Excellent !!!!!

    Best regards.

    Thread Starter dwaynne

    (@dwaynne)

    No success with that approach so I am trying something like this:

    
    <script type="text/javascript">
    var jq94 = jQuery.noConflict();
    jq94(document).ready(function(){
    	jq94("#field_1-20").hide();
        if(jq94("#fieldname11_1").val() !=='' ){
    		jq94("#field_1-20").addClass("test");
    		jq94("#field_1-20").show();
    	}  
        else{
            jq94("#field_1-20").hide(); 
            }
        });
    </script>

    Where #field_1-20 is the entire field container and #fieldname11_1 is the input to receive the calculated result.

    Plugin Author codepeople

    (@codepeople)

    Hello @dwaynne

    I recommend you the following solution:

    1. Remove the piece of code in your entry because it does not run when the fieldname11 changes its value.

    2. Edit the equation in the fieldname11 as follows:

    (function () {
        var result = '', f = getField(11).jQueryRef();
        if(fieldname3 == 'Common Law' && fieldname6 == 'Mortgage financing') result = fieldname8 + fieldname9;
        else if(fieldname3 == 'Common Law' && fieldname6 == 'No mortgage financing') result = '';
        else if(fieldname3 == 'RPA' && fieldname6 == 'No mortgage financing') result = '';
        else if(fieldname2 > 0 && fieldname6 == 'No mortgage financing') result = fieldname8 + fieldname9;
        
        if(result == ''){f.hide(); return result;} 
        f.show(); return PREC(result,2);
    })()

    Best regards.

    Thread Starter dwaynne

    (@dwaynne)

    Works like a charm! Thanks a mil’, @codepeople!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Conditionally display fields based on calculation result’ is closed to new replies.