React Advanced Form
  • Introduction
  • General
    • Comparison
      • Compared to Formik
      • Compared to Final form
    • Migration guides
      • 1.4.x → 1.5.x
    • FAQ
  • Getting started
    • Installation
    • Creating fields
    • Creating form
    • Validation rules
    • Validation messages
    • Applying validation
    • Handle submit
  • Architecture
    • Argument properties
    • Referencing
    • Field lifecycle
    • Controlled fields
    • Reactive props
  • Validation
    • Getting started
    • Validation schema
      • Rule definition
      • Reactive rule
    • Validation messages
  • High-order components
    • createField
      • Options
      • Field presets
      • Exposed props
  • Components
    • FormProvider
    • Form
      • Props
        • innerRef
        • initialValues
        • action
        • rules
        • messages
      • Methods
        • setValues()
        • setErrors()
        • reset()
        • validate()
        • serialize()
        • submit()
      • Callbacks
        • onFirstChange
        • onReset
        • onInvalid
        • onSerialize
        • onSubmitStart
        • onSubmitted
        • onSubmitFailed
        • onSubmitEnd
    • Field.Group
    • Field
      • Props
        • rule
        • asyncRule
        • skip
      • Callbacks
        • onFocus
        • onChange
        • onBlur
  • Recipes
    • Generating a form
    • Utilizing functions
  • Developers
    • Contributing
Powered by GitBook
On this page
  • Definition
  • Declaration
  1. Validation
  2. Validation schema

Reactive rule

Any validation resolver may become reactive. This means that it is being re-evaluated anytime the field prop references established in its declaration change.

Definition

type Get = (fieldPropPath: string[]) => any

Declaration

Use get function from the resolver parameters to reference other fields' props.

validation/rules.js
export default {
  name: {
    confirmPassword: ({ get, value }) => {
      return value === get(['password', 'value'])
    }
  }
}

The resolver above marks confirmPassword field as valid whenever its value equals to the value of the password field. This rule is automatically re-evaluated in real time whenever the values of either fields update.

Use reactive rules when the validity of a field depends on some props of another field(s).

PreviousRule definitionNextValidation messages

Last updated 6 years ago