Strickland
  • Readme
  • Introduction
    • Validators
    • Validation
    • Validation Results
  • Extensibility
    • Validator Factories
    • Validation Context
    • Validation Result Props
    • Extensibility Pattern
    • formatResult
  • Built-In Validators
    • required
    • compare
    • min
    • max
    • range
    • minLength
    • maxLength
    • length
  • Composition
    • Arrays of Validators
      • every
      • all
      • some
    • Validating Array Elements
      • arrayElements
    • Validating Objects
      • objectProps
      • Advanced Object Validation
      • Nested Objects
      • Arrays of Objects
    • Composition Conventions
    • Composition and formatResult
  • Async Validation
    • Resolving Async Validation
    • Deferred Async Validation
    • Async Validator Arrays and Objects
    • Two-Stage Sync/Async Validation
    • Race Conditions
    • Automatic Race Condition Handling
    • Async Validation and formatResult
  • Form Validation
    • form
    • Async Form Validation
    • validateFields
    • emptyResults
    • updateFieldResults
  • Inspiration
  • Design Goals
  • Wrap-Up
  • Change Log
  • NPM
  • GitHub
Powered by GitBook
On this page
  • Field-Level Async Validation
  • Two-Stage Validation

Was this helpful?

  1. Form Validation

Async Form Validation

PreviousformNextvalidateFields

Last updated 4 years ago

Was this helpful?

Async validation works naturally with the form validator. Any validator within the form validation can use async validation. As is seen with objectProps and other composition validators, an async validator within a form will result in a validateAsync function on the validation result.

Field-Level Async Validation

By default, the validateAsync function returned on the validation result will resolve async validation for all fields that have remaining async validation. But, the validateAsync function also accepts a context parameter that allows specific fields to be resolved using the same form.fields behavior defined for synchronous form validation.

// Execute async validation only for the username field
const asyncContext = {
    form: {
        fields: ['username']
    }
};

result.validateAsync(formValues, asyncContext);

Two-Stage Validation

is commonly used with forms where standard validation occurs synchronously with results immediately rendered, but async validation that calls an API will be rendered when the response comes back.

Two-Stage Validation