How to search for nothing in a

Viewing 3 reply threads
  • Author
    Posts
  • December 8, 2020 at 9:07 AM #42818

    Victor Warner
    Participant

    I wish to create a script which searches one Number field. If there is nothing there then use another Number field. However, if the first number may have nothing in it (not even a zero), but I cannot work out the search criteria for an empty number field.

    For example:

    if (upper_figure == ”) {
    return total_charge_with_fixed_amount;

    }

    does to produce the desired result if the upper_figure is empty. Nor does

    if (upper_figure == null) {
    return total_charge_with_fixed_amount;

    }

    What is the correct syntax for an empty Number field?

    December 8, 2020 at 9:17 AM #42819

    Daniel Leu
    Participant

    Try if (upper_figure == undefined || upper_figure == "") {

    December 9, 2020 at 10:16 AM #42823

    Victor Warner
    Participant

    Daniel,

    Thank you again.

    Brendan,

    Could you put on the relevant help pages information on searching for nothing for different types of field? It is not easily found and confuse beginners in Javascript. I am used to searching in other apps for nothing with either ” or “” but these do not necessary work with TapForms for some field types.

    December 9, 2020 at 9:56 PM #42826

    Sam Moffatt
    Participant

    If you’re after checking if something isn’t “falsy” then you could simplify it to if (!upper_figure) { and JavaScript will convert it for you automatically. Per that falsy page though, it will treat zero as false.

    Some of the nuance is that if you haven’t set a value on a field then it is undefined because it hasn’t been set yet. Tap Forms for many field types maps directly to JavaScript data types. JavaScript will do some amount of type coercion which may result in unexpected results.

Viewing 3 reply threads

You must be logged in to reply to this topic.