Validator

Description

The Validator is a utility component designed to orchestrate and centralize the validation of multiple UI elements. It registers components that implement validation, tracks which of them the user has interacted with, and triggers visual state updates based on their current validity. Use this component when you need to validate forms or groups of input components in a fluent and efficient manner.

Usage

Instantiate the Validator using the static helper from Tesserae.UI. Register your UI components (such as TextBox or Dropdown) with custom validation logic. This allows you to show validation messages dynamically as users interact with the form or when the entire form is revalidated (for instance, on form submission).

Below is a simple example demonstrating its usage:

API reference

class

Validator

public sealed class Validator

A Validator class that coordinates validation for multiple components.

Namespace
Tesserae

Constructors

NameDescription
ValidatorInitializes a new instance of the Validator class.
Constructor
Validator
public Validator()

Initializes a new instance of the Validator class.

Properties

NameDescription
IsValidThis will trigger the validation logic for EVERY registered component and return false if any of them are not in a valid state (and, by doing so, their display state will be updated accordingly)
Property
Validator.IsValid
public bool IsValid { get ; }

This will trigger the validation logic for EVERY registered component and return false if any of them are not in a valid state (and, by doing so, their display state will be updated accordingly)

Methods

NameDescription
OnValidationHandlerThe haveEncounteredInvalidValue value indicates whether any invalid values have been encountered SO FAR - components will only be validated as a User edits them OR when a Revalidate call is made (or the IsValid property is checked), which indicates an action such a form submission is about to occur and that EVERYTHING should be checked (unless such an action has occurred, we want to give Users a chance to fill things in BEFORE we shout at them about it)
Register<T>Registers a component with the validator.
ResetStateResets the validation state of all registered components.
RegisterFromCallbackRegisters a custom validation logic not tied to a specific component.
OnValidationAdds a validation event handler.
DebounceSets the debounce delay for validation. The milliseconds must be a value of at least one, trying to disable Debounce by passing a zero (or negative) value is not supported.
AreCurrentValuesAllValidThis will check whether the form's values would currently be considered valid but without updating any the visual states relating to validity - this may be used when a form is being displayed to the User where the fields MIGHT all have been pre-populated and so the form may be valid already (but if it's not valid yet then we don't want the fields that the User hasn't edited yet to be shown as invalid until they've had a chance to interact with them). This would be used if the submit on the form should be set to disabled initially if the form is invalid (or enabled if IS valid) and subsequently updated on each ValidationOccured event.
RevalidateTriggers validation for all registered components and returns whether they are all valid.
GetValidityThis will return false if any of the components that were checked were found to be in an invalid state (the components checked depends upon validateOnlyUserEditedComponents and which registered components that the User has interacted with)
Delegate
Validator.OnValidationHandler
public delegate void OnValidationHandler(ValidationState validity)

The haveEncounteredInvalidValue value indicates whether any invalid values have been encountered SO FAR - components will only be validated as a User edits them OR when a Revalidate call is made (or the IsValid property is checked), which indicates an action such a form submission is about to occur and that EVERYTHING should be checked (unless such an action has occurred, we want to give Users a chance to fill things in BEFORE we shout at them about it)

Method
Validator.Register<T>
public void Register<T>(ICanValidate<T> component, Func<bool> wouldBeValid, Action validate) where T : ICanValidate<T>

Registers a component with the validator.

Type Parameters

T
The type of the component.

Parameters

component
The component to register.
wouldBeValid
A function that returns whether the component would be valid without updating its visual state.
validate
An action that performs validation and updates the component's visual state.
Method
Validator.ResetState
public void ResetState()

Resets the validation state of all registered components.

Method
Validator.RegisterFromCallback
public void RegisterFromCallback(Func<bool> isInvalid, Action onRevalidation)

Registers a custom validation logic not tied to a specific component.

Parameters

isInvalid
A function that returns whether the state is invalid.
onRevalidation
An action to perform on revalidation.
Method
Validator.OnValidation
public Validator OnValidation(OnValidationHandler onValidation)

Adds a validation event handler.

Parameters

onValidation
The validation event handler.

Returns

The current instance of the type.

Method
Validator.Debounce
Overload
Debounce(int)Sets the debounce delay for validation. The milliseconds must be a value of at least one, trying to disable Debounce by passing a zero (or negative) value is not supported.
Debounce(int, int)Sets the debounce delay and maximum delay for validation.
Debounce(int)
public Validator Debounce(int delayInMs)

Sets the debounce delay for validation. The milliseconds must be a value of at least one, trying to disable Debounce by passing a zero (or negative) value is not supported.

Parameters

delayInMs int
The delay in milliseconds.

Returns

The current instance of the type.

Debounce(int, int)
public Validator Debounce(int delayInMs, int maxDelayInMs)

Sets the debounce delay and maximum delay for validation.

Parameters

delayInMs int
The delay in milliseconds.
maxDelayInMs int
The maximum delay in milliseconds.

Returns

The current instance of the type.

Method
Validator.AreCurrentValuesAllValid
public bool AreCurrentValuesAllValid()

This will check whether the form's values would currently be considered valid but without updating any the visual states relating to validity - this may be used when a form is being displayed to the User where the fields MIGHT all have been pre-populated and so the form may be valid already (but if it's not valid yet then we don't want the fields that the User hasn't edited yet to be shown as invalid until they've had a chance to interact with them). This would be used if the submit on the form should be set to disabled initially if the form is invalid (or enabled if IS valid) and subsequently updated on each ValidationOccured event.

Method
Validator.Revalidate
public bool Revalidate()

Triggers validation for all registered components and returns whether they are all valid.

Returns

True if all components are valid, false otherwise.

Method
Validator.GetValidity
private ValidationState GetValidity(bool validateOnlyUserEditedComponents, bool updateComponentAppearances)

This will return false if any of the components that were checked were found to be in an invalid state (the components checked depends upon validateOnlyUserEditedComponents and which registered components that the User has interacted with)

Form

A real <form> container. Wrapping login inputs in one (with Action and proper autocomplete hints on the inputs) is what lets browser and third-party password managers detect the submission, scope saved credentials to the current origin rather than falling back to registrable-domain heuristics, and prompt the user to save or update the password.

class

Form

public class Form : IContainer<Form, IComponent>, IHasMarginPadding

A <form> container. Wrapping login inputs in a real form (with Action and proper autocomplete hints on the inputs) is what lets browser and third-party password managers detect the submission, scope saved credentials to the current origin (subdomain included) instead of falling back to registrable-domain heuristics, and prompt the user to save or update the password.

Namespace
Tesserae
Implements
IContainer<Form, IComponent>, IHasMarginPadding

Properties

NameDescription
ActionThe form's submission URL. Should be a same-origin URL (absolute or relative) on the current subdomain — this is the strongest hint a password manager has for scoping the saved credential to location.host rather than to the registrable domain.
MethodThe form's HTTP method (defaults to post).
FormNameThe form's name attribute.
AutoCompleteThe form-level autocomplete attribute (on / off). Leave unset to inherit the browser default. Setting this to off disables saving for the whole form, which is the opposite of what a sign-in form usually wants.
Property
Form.Action
public string Action { get ; set ; }

The form's submission URL. Should be a same-origin URL (absolute or relative) on the current subdomain — this is the strongest hint a password manager has for scoping the saved credential to location.host rather than to the registrable domain.

Property
Form.Method
public string Method { get ; set ; }

The form's HTTP method (defaults to post).

Property
Form.FormName
public string FormName { get ; set ; }

The form's name attribute.

Property
Form.AutoComplete
public string AutoComplete { get ; set ; }

The form-level autocomplete attribute (on / off). Leave unset to inherit the browser default. Setting this to off disables saving for the whole form, which is the opposite of what a sign-in form usually wants.

Methods

NameDescription
OnSubmitAttaches a handler invoked when the form is submitted (via Enter on a child input or a <button type="submit"> inside the form). The native browser navigation is always cancelled.
SubmitProgrammatically request submission (mirrors pressing Enter inside the form). Uses HTMLFormElement.requestSubmit() when available so that validation runs and the submit event fires; otherwise falls back to dispatching a synthetic event.
Method
Form.OnSubmit
public Form OnSubmit(ComponentEventHandler<Form, Event> onSubmit)

Attaches a handler invoked when the form is submitted (via Enter on a child input or a <button type="submit"> inside the form). The native browser navigation is always cancelled.

Method
Form.Submit
public Form Submit()

Programmatically request submission (mirrors pressing Enter inside the form). Uses HTMLFormElement.requestSubmit() when available so that validation runs and the submit event fires; otherwise falls back to dispatching a synthetic event.

Samples

Basic Form Validation Example

The following sample demonstrates how to set up a simple form with two text boxes. Each text box has its own validation logic, and a validator is used to update the UI based on the current validity of the form.

See also

  • TextBox: Often used in forms alongside Validator.
  • Dropdown: Another input component that can be validated.
© 2026 Curiosity. All rights reserved.