Preventing Negative Values in Form Calculation Widget

  • JBL
    Asked on February 22, 2017 at 3:47 PM

    I need to prevent negative values from being entered as gratuity.

    I used the formula "max (0, )" to prevent negative values from being entered. This results in a default of 0 in the field. I prefer to have the field remain blank. Is there any other way to prevent negative values from being entered?

  • Nik_C
    Replied on February 22, 2017 at 7:03 PM

    Unfortunately, with Form calculations widget I don't see the way to do that since as soon as you click the field involved in calculation number zero is inserted no matter what. But, it is possible with regular number field.

    I used a simple example with two numbers that are calculated and shown in calculation field (also number field):

    Preventing Negative Values in Form Calculation Widget Image 1 Screenshot 50

    I created two calculation fields that are identical with identical calculation max(0,number1-number2):

    Preventing Negative Values in Form Calculation Widget Image 2 Screenshot 61

    I created two fields because we need to check if the field is zero, insert blank into it. And we can not do that with the same field, we need to have a temp one which is calculation number 1 (note: you can make those two fields be named the same).

    Also, I created a calculation that if calculation number equals zero insert blank into calculation number1:

    Preventing Negative Values in Form Calculation Widget Image 3 Screenshot 72

    And finally, if calculation number equals zero I show calculation number1(which is with blank space already):

    Preventing Negative Values in Form Calculation Widget Image 4 Screenshot 83

    And I hide the calculation number (the original one) which is with zero in it.

    Since they do the same calculation your user will not even notice when they change (again, you can make them name the same).

    I understand it is not an elegant solution, but that is what I came out to.

    Please let us know your thoughts.

    Thank you!

  • JBL
    Replied on February 23, 2017 at 7:56 AM

    Thank you for looking into it. I will try your solution.