how can i show hide section if the calculated field is greater than a certain amount?

Confluence User - 30 Sep, 2024

Hi experts,

I'm currently having some issues showing or hiding sections if a calculated field is greater than a certain amount.

I have tried using the regex value in the field value of the visibility control of the section that I want to show or hide, but it didn't seem to work. 

any advise or some solution on getting this to work. 

Thank you in advance.

forms

10


30 Sep, 2024
confluenceUser
confluenceUser

Hi Hironori, Can you check if you have enabled store as numeric value? instead of regex try giving the value directly using the "Greater than or equal to" Operator. Please refer the sample app attached demonstrating your usecase.

APP_calculationField-1-20240930120703.jwa

Hope this helps.

01 Oct, 2024
confluenceUser
confluenceUser

Hi Varnaa,

Thank you for your reply. 

After viewing your sample app in the section visibility control → field value, i didn't see the "Greater than or equal to" operator.

Joget2.png


With your sample app I have tried adding the operator in the field value and running the application, but the show or hide also didn't seem to work.

01 Oct, 2024
confluenceUser
confluenceUser


The above screenshot is from Joget version 8.1.1 which now supports operators and grouping.

Adding operator in the field value will not work as the whole string is used to compare. Can you try enabling the regex option and try ^(1\d{2}|[2-9]\d{2,}|[1-9]\d{3,})$ in the field value. Additionally you can also test and understand the regex using  https://regex101.com/.


01 Oct, 2024
confluenceUser
confluenceUser

Hi Varnaa,

Thank you for your reply. 

So basically, in version 7 the only way to achieve this is to use regex? or is there a workaround?

01 Oct, 2024
confluenceUser
confluenceUser

I am not able to think of any other workaround sorry. If its static value like 100 then you can use non-regex option but since you have calculation field that needs to be checked for >=somevalue regex should get the job done. 

01 Oct, 2024
confluenceUser
1
confluenceUser

Hi
You can write a small jquery script that stores the following values in a hidden field (lets say result) based on your calcualtion field:

result =

1 if greater than amount

2 if less than amount

3 if equal


Using result field you can apply section visibility

02 Oct, 2024
confluenceUser
confluenceUser

ok thank you for your advice.

02 Oct, 2024
confluenceUser
confluenceUser

Hi Anas Misbah Shami

Do you have any sample jQuery?

I have tried adding the data validation in the Total USD calculated field as per below:

<script>
$(document).ready(function() {
    // Ensure the script runs after the form is fully loaded
    FormUtil.onReady(function() {
        // Initially hide the section
        $('#ADSection').hide();

        // Function to show or hide section based on calculation field value
        function checkCalcField() {
            var calcValue = parseFloat($('#gtotalCur').val().replace(/,/g, '')); // Parse the input value and remove commas

            if (calcValue > 10000) {
                // Show the section if value is greater than 10,000
                $('#ADSection').show();
            } else {
                // Hide the section if value is less than or equal to 10,000
                $('#ADSection').hide();
            }
        }

        // Listen for changes in the calculation field
        $('#gtotalCur').on('change keyup', function() {
            checkCalcField();
        });

        // Initial check in case the field is pre-filled
        checkCalcField();
    });
});
</script>

but didn't work.  or should it be in a custom HTML?


Thank you in advance

02 Oct, 2024
confluenceUser
confluenceUser

Yes you need to add a custome HTML component and write the script in it

04 Oct, 2024
confluenceUser
confluenceUser

Thank you; I managed to settle with the custom HTML.

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print