MENU
    blockIfEmpty
    • 13 Nov 2020
    • 1 Minute to read
    • Contributors
    • Dark
    • PDF

    blockIfEmpty

    • Dark
    • PDF

    Article summary

    Description

    Queues a validation block for an input object(s), conditioned on a value not having been specified by the user. When active, this block will prevent the user from continuing for the specified reason.


    Input Parameters

    NameTypeRequiredDescription
    tokenTextYesInput object token (i.e. [5])
    reasonTextYesReason displayed to the user for being blocked
    [type]TextNo'all' = Blocks if all objects are empty (default); 'any' = Blocks if any object is empty

    Returns

    No return value.


    Examples

    // block the user if a value for input object [5] is missing
    user.blockIfEmpty("[5]", "You must specify a pressure value.");
    JavaScript
    // block if both input objects [5] and [10] are empty
    // note: specifying 'all' is not required since this is the default behavior
    user.blockIfEmpty("[5], [10]", "You must specify a pressure value.", "all");
    JavaScript
    // block if either input objects [5] and [10] is empty
    user.blockIfEmpty("[5], [10]", "You must specify a pressure value.", "any");
    JavaScript

    Remarks

    Definition

    Validation is the process of making sure user inputs contain appropriate values. For example, if numbers are within an expected range or if required values are even entered at all.

    Products that run your apps will typically support a feature where your app's user inputs are validated at some point in time (i.e. when the user tries to save their work).

    You can hook into the validation process using the blocking functions.

    • blockIfEmpty(...) - blocks user if a value is missing
    • blockIfValue(...) - blocks user if a specific value is entered
    • block(...) - blocks user (without a condition)
    Validation Process

    The runtime's validation process performs these steps when it's time to validate the user's inputs:

    1. The user performs an action that triggers validation (i.e. save).
    2. Your app's Ux.Validate script runs. This is your opportunity to add all the blocks you want via the available blocking functions. They are queued in the order they are added in your script.
    3. The runtime checks to see if any blocks are queued.
    4. If so, it displays a list of your blocking messages to the user and prevents them from continuing.
    5. If no blocks are queued, the user's action will proceed.
    6. All validation blocks are reset (cleared).

    What's Next