FormState

class FormState<T>(initialValue: T, val validator: <Error class: unknown class><T>, val validationMode: ValidationMode = ValidationMode.OnChange, val failFast: Boolean = false)

Manages mutable form state and validation status for a target value object T.

Provides fields tracking (dirtyFields, touchedFields), validation triggers (onFieldChange, onFieldBlur), and async form submission helpers.

Parameters

T

The type of value or data class held by the form state.

initialValue

The starting value of the form.

validator

The ValixValidator compiled instance used to validate form data.

validationMode

Strategy determining when validation is triggered (ValidationMode.OnChange, ValidationMode.OnBlur, etc.).

failFast

If true, validation terminates immediately upon encountering the first error.

Constructors

Link copied to clipboard
constructor(initialValue: T, validator: <Error class: unknown class><T>, validationMode: ValidationMode = ValidationMode.OnChange, failFast: Boolean = false)

Properties

Link copied to clipboard
val dirtyFields: <Error class: unknown class>

Set of field names that have been modified.

Link copied to clipboard
val errors: List<<Error class: unknown class>>

Returns list of current validation errors.

Link copied to clipboard
val failFast: Boolean = false
Link copied to clipboard
val fieldErrors: Map<String, <Error class: unknown class>>

Returns current errors indexed by property field name.

Link copied to clipboard

true if any field value has been modified since initialization or reset.

Link copied to clipboard

true if the form submission has been triggered.

Link copied to clipboard

true while the form submission callback is currently executing.

Link copied to clipboard

true if any field has lost focus.

Link copied to clipboard

Returns true if current validation result is valid.

Link copied to clipboard
val touchedFields: <Error class: unknown class>

Set of field names that have lost focus.

Link copied to clipboard
Link copied to clipboard
var validationResult: <Error class: unknown class>

The current ValidationResult.

Link copied to clipboard
val validator: <Error class: unknown class><T>
Link copied to clipboard
var value: T

The current value instance.

Functions

Link copied to clipboard

Clears all validation errors while keeping values intact.

Link copied to clipboard
fun errorFor(field: String): <Error class: unknown class>?

Returns the first ValidationError for the specified field, or null.

Link copied to clipboard
fun onFieldBlur(field: String)

Triggers field blur tracking and executes validation if mode is ValidationMode.OnBlur.

Link copied to clipboard
fun onFieldChange(field: String, newValue: T)

Triggers field update and executes validation if mode is ValidationMode.OnChange.

Link copied to clipboard
fun reset(initialValue: T)

Resets the form state to initialValue and clears all error/dirty state.

Link copied to clipboard
suspend fun submit(vararg groups: KClass<*>, onExecute: suspend (T) -> Unit)

Validates and executes onExecute if validation passes.

Link copied to clipboard
fun validate(vararg groups: KClass<*>): <Error class: unknown class>

Manually triggers validation for the specified groups.