Search Results for

    Show / Hide Table of Contents

    Form validation

    Validating data is always the most critical step in every business workflow, especially where it requires user interaction. Understanding the challenge, Casewhere offers many validation methods that work out of the box for developers while still giving them the flexibility to implement the most complex business requirements.

    Basic validation configuration

    Required validation

    All form component has a property Required. When the property is enabled, users must enter a value in order to submit the form successfully. It's possible to customized the Required Message, which will be displayed to the end users. The Required Message accepts a text resource key.

    The example below shows how the property is configured in Casewhere Admin: the field Full name is required, and its Required Message is the text resource key docs_full_name_is_required, whose English text is "Full name is required".

    Required and Required Message of a field

    Here is how the validation works for end users on a worker site: when a user tries to save the form without a full name, the form shows the Required Message under the field.

    The Required Message under the empty Full name field on a worker site

    Component-specific validation

    Each form component has a different set validation properties. Below are some typical components and their validation properties you might usually work with.

    Component Property Description
    Textbox Max Length The maximum number of characters allowed
    Textbox Min Length The minimum number of characters required in an input field
    Numeric Textbox Max Value The maximum value
    Numeric Textbox Min Value The minimum value
    Datepicker Max Date The maximum value
    Datepicker Min Date The minimum value
    File Upload File Extensions The acceptable file extensions
    File Upload File Size The maximum size in MB allowed to be uploaded
    Masked Textbox Mask The pattern of input

    Component validation rules

    Since version 2.7.2, we recommend configuring validation rules at the component-level instead of managing them at the form-level in previous versions.

    Casewhere allows configuring validation rules for form components. Select the component you want to validate, in the Properties tab pane, select Validation Rules. It's possible to add multiple validation rules for a component. Components having validation rules will have a green tick icon in the form editor.

    The validation rules of a field

    A validation rule is a boolean expression. The validation passes if the rule returns true. The rule accepts the @ctx keyword to access the workflow data. You can learn more about writing rules here.

    Example: Verify that users enter an email address that no other applicant has (the rule Email must be unique above)

    #predicate
    
    var dataApi = ctx.Use<IDataApi>();
    
    var email = ctx.FormData["DocsWfApplicant"]["Email"];
    var id = ctx.FormData["DocsWfApplicant"]["Id"];
    
    var filter = FilterBuilder.Create().Eq("Email", email).Ne("_id", id).Build();
    var any = dataApi.Any("DocsWfApplicant", filter);
    return !any;
    

    Instant validation

    By default, Casewhere only validates when users submit data, i.e., click the save button in the workflow wizard. Many applications trigger validation right after users input data to improve user experience. Understanding the need, Casewhere supports instant validation that triggers validations based on various component events by utilizing the same validation rules.

    To enable instant validation, set Validation Enable Async to True and then specify a value for the property Validation Async Trigger. For example, if Blur is selected, when users focus out the component, Casewhere will immediately trigger the data validation on that component. An error message will be displayed if the validation fails, just like when submitting form data.

    Please note that sending excessive validation requests while users are typing can be frustrating for end users and place unnecessary strain on the server. To address this, it's recommended to implement a debounce for value updates using the Update Option setting.

    The Update Option of a field

    In This Article
    Back to top Generated by DocFX