How to make calculations only when a number is added into a textbox?

  • Profile Image
    Asked on September 08, 2015 at 10:59 AM


    I have a form "Program fee [NZ]" which includes the Form Calculations widget.

    I have set the following option as TRUE in the advanced options of the widget:

    "Wait for input before including the field in calculation."

    The formula I have is {enternumber} * 125 + 145

    The problem I am having is that as soon as the user clicks in the input field, it displays 145. I do not want a value to show until the user enters a number.

    When the user enters a number, such as 1, it correctly displays the correct value (270). But if the user deletes the number, it shows 145 again. I would like your help please to prevent 145 from showing when the field is blank and selected.

    Thank you in advance for any help you can provide.

  • Profile Image
    Answered on September 08, 2015 at 12:31 PM

    The best way to do this is to do the calculations through the conditions.

    This is because you will need to make several checks and when something like that is needed, conditions are our best friend.

    What I decided to go with is to check if the field is filled out or not and then if it is filled out to also check if the value is greater than 0 - since the question above does seem as if you are expecting a positive number.

    Once this is done, we just set it all as if want and set it to update our read only textbox.

    Conditions setup:

    And we set up the textbox as read only through its properties:

    You can see a clone of your form with that setup and the textbox field added by checking out this form:

    I intentionally left the form calculation so that you can see them both working in the same time, but it can be removed :)

    Do let us know how it goes.

  • Profile Image
    Answered on September 10, 2015 at 08:05 AM

    Hi Ben!

    Thank you very much for your detailed answer. The clone form you made is exactely the result I am looking for. Unfortunately, I am having trouble replicating the form your created because your screenshots do not match what I see on my screen. I can open the form calculations plugin screen and this is what I see:

    There is no option that I can see to add conditions fields to the top of the calculation wizard screen as you have on your screenshot. I can close that screen and choose the properties (Cog wheel) of the calculated program fee field, and then it will show the conditions fields as shown below:

    However, the only options I get in the "Then" section are to show the entire calculated fee field, which is not what you managed to achieve on your demo form.

    Looking forward to your response. Thanks again!

  • Profile Image
    Answered on September 10, 2015 at 09:15 AM

    OK, I see, and I apologize for the confusion.

    What I did uses the conditions as shown here: How to Insert Text or Mathematical Calculation into a field using a Condition

    We are basically going around the form calculation widget completely and just using these conditions.

    When you follow the steps above, you will see how to get to the conditions part that not only allows you to show and hide the field, but to also allow you to insert the value and many other things:

    Do let us know how it goes and if you have any questions or need any assistance.

  • Profile Image
    Answered on September 10, 2015 at 10:30 AM

    Thank you for the clarification Ben! That works for me, and will be of great use for future forms I make too.