Enum Class ValidationTrigger

java.lang.Object
java.lang.Enum<ValidationTrigger>
com.oorian.validation.ValidationTrigger
All Implemented Interfaces:
Serializable, Comparable<ValidationTrigger>, Constable

public enum ValidationTrigger extends Enum<ValidationTrigger>
Defines when validation should be triggered for a validated input.

ValidationTrigger controls the automatic validation behavior of validated inputs. Different triggers provide different user experiences - some validate immediately, others wait for user interaction.

Recommended Approach: Use BLUR_THEN_CHANGE for most fields. This provides the best user experience by not showing errors while typing, but providing immediate feedback after the user has completed initial input.

Usage:


 ValidatedInput<String> email = new ValidatedInput<>(emailInput, emailError)
     .required()
     .email()
     .validateOn(ValidationTrigger.BLUR_THEN_CHANGE);
 
Since:
2025
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Enum Constant Details

    • BLUR

      public static final ValidationTrigger BLUR
      Validate when the field loses focus.

      This is a good default for most fields. Validation runs when the user tabs or clicks away from the field, providing feedback without interrupting typing.

    • CHANGE

      public static final ValidationTrigger CHANGE
      Validate on every value change.

      Provides immediate feedback as the user types. Use sparingly as it can be distracting and generates many validation requests. Best suited for fields where immediate feedback is valuable, such as password strength indicators.

    • SUBMIT

      public static final ValidationTrigger SUBMIT
      Validate only on form submission.

      Defers all validation until the user attempts to submit the form. Good for performance-sensitive forms or when you prefer a traditional form experience.

    • BLUR_THEN_CHANGE

      public static final ValidationTrigger BLUR_THEN_CHANGE
      Validate on blur first, then on every change after that.

      This provides the best user experience for most cases:

      1. User enters a value and moves to the next field
      2. First validation runs on blur
      3. If invalid, subsequent changes trigger immediate validation
      4. If valid, changes don't trigger validation until blur again

      This avoids showing errors while the user is still typing their initial input, but provides immediate feedback once they're trying to correct an error.

    • MANUAL

      public static final ValidationTrigger MANUAL
      Never auto-validate; only validate when explicitly called.

      Use this when you want full control over when validation occurs, such as wizard-style forms where validation happens on step navigation.

  • Method Details

    • values

      public static ValidationTrigger[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ValidationTrigger valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null