Forcing a calculation field when result is less than real operation

Confluence User - 09 Jul, 2024

I there experts. In the calculated field i am multiplying a *  b. But i want  when the result of the operation is less then a given number (for exemple less than 2, the value that is showned is 100. For example, if a * b is 2, the value of the calculated field should be 100, instead of real result (2). Resuming, the user should see 100, when the result of the operation is less than 2. 

is there any easy way to do this without  code?


Thanks

forms

4


11 Jul, 2024
confluenceUser
confluenceUser

make calculation field hidden. use section visibility conditions 

Section - Knowledge Base for DX 8 - Joget | COMMUNITY

assuming you're using the latest joget dx 8 version check the value of the calculation field

if its 2 or below, show this section with a label/field that says 100 (hardcoded maybe?)

then another section that will be visible based on the visibility  condition of 2 or more to show whatever you need to show

12 Jul, 2024
confluenceUser
1
confluenceUser

hi, 
the arithmetic operator in the calculation field Operation field cannot handle the conditional logic
This is the low code way.
Just simply have a custom html and apply this javascript to have the conditional formatting to work.

 

<script>
    // Function to perform calculation and apply conditional logic
    function calculateAndFormat() {
        var a = parseFloat(document.getElementById("a").value);
        var b = parseFloat(document.getElementById("b").value);
        var result = a * b;

        if (result <= 2) // Adjust here according to the value you wanted to control
        {
            result = 100;
        }

        document.getElementById("result").value = result;
    }

    // Event listeners to trigger calculation when input changes
    document.getElementById("a").addEventListener("input", calculateAndFormat);
    document.getElementById("b").addEventListener("input", calculateAndFormat);
</script>

Sample app for you too : APP_calculateField-1-20240712143933.jwa

12 Jul, 2024
confluenceUser
confluenceUser

Thank you for the suggestion, but its not a visibility issue.

12 Jul, 2024
confluenceUser
confluenceUser

Hi there, had no ideia that this could be done. Thank for your time and for the example app, it will solve my problem. Regards.

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print