• Resolved Helen

    (@web09)


    Hello,
    I have created a conversion calculator using the Calculated Field Forms plugin. I would like to only allow calculations with positive numbers (equal or greater than 0). In the form settings I already have set the minimum value to 0, so when a negative number is written, the field shows the error message as it should be, however the form still calculates and shows a result. What should I write in the equation so it doesn’t perform the calculation? In the equation editor I have already the following equation that limits the result to 2 decimal places:
    (function(){
    function countDecimals (value) {
    if ((value % 1) != 0)
    return value.toString().split(“.”)[1].length;
    return 0;
    };

    var result = fieldname11*14.5;

    if(2<countDecimals(result)) return PREC(result,2);
    return result;
    })()

    Thank you,

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @web09

    You simply should to use an if conditional statement as part of the equation:

    
    (function(){
        if(fieldname11<0) return '';
    
        function countDecimals (value) {
            if ((value % 1) != 0) return value.toString().split(".")[1].length;
            return 0;
        };
    
        var result = fieldname11*14.5;
    
        if(2<countDecimals(result)) return PREC(result,2);
        return result;
    })()
    

    and that’s all.
    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘CCF plugin – Disable calculation with negative numbers’ is closed to new replies.