FormState

class FormState

Reactive state of all form controls.

FormState holds and manages the states of all controls in the form, using the Compose State API so the UI recomposes automatically on changes.

Main functions:

  • Holding reactive control states (MutableState)

  • Triggering recomposition on changes

  • Managing hierarchical control names (e.g. for RepeatableControl)

  • Collecting data from all controls for processing

Control states are keyed by full path (e.g. "publicationsuuid.title"), which is what supports complex, nested structures.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
private val _controlStates: SnapshotStateMap<String, ControlState<*>>

Control states - a reactive map that triggers recomposition automatically

Link copied to clipboard
val actionTriggered: MutableState<Boolean>

Form submission flag (triggerAction). True while an action (e.g. save, delete) is running.

Link copied to clipboard
val loadState: MutableState<FormLoadState>

Stage of loading the initial data (initData). Until it is FormLoadState.Loaded the controls have no states, so there is nothing to draw.

Functions

Link copied to clipboard

Collects and processes the data of all form controls.

Link copied to clipboard

Collects the results of the controls of one data level under their names. Containers collect their own levels, with this same function: a section once, a repeatable per row. Every control gets a context with its parent, because only that tells whether it is visible - and an invisible one passes no value to save.

Link copied to clipboard

Returns the states of all form controls

Link copied to clipboard

Returns the state of the control with the given name

Link copied to clipboard
internal fun initializeLevel(levelPath: String, controls: List<Pair<ControlContext, Control<*>>>, values: Map<String, Any?>)

Creates the control states of one data level - the form, a section or a repeatable row - from the values under their names. Containers set up their own levels in setInitValue, with this same function.

Link copied to clipboard
internal fun initializeStates(schema: FormSchema, initValues: Map<String, Any?>)

Initializes the states of all controls from the initial values.

Link copied to clipboard
private fun pathIn(levelPath: String, name: String): String
Link copied to clipboard
internal fun removeControlState(name: String)

Removes the state of the control with the given name Triggers recomposition automatically thanks to mutableStateMapOf

Link copied to clipboard

Removes all control states starting with the given prefix Triggers recomposition automatically thanks to mutableStateMapOf

Link copied to clipboard
internal fun setControlState(name: String, state: ControlState<*>)

Sets the state of the control with the given name (may be hierarchical) Triggers recomposition automatically thanks to mutableStateMapOf

Link copied to clipboard
private fun valuesByName(levelPath: String, values: Map<String, Any?>): Map<String, Any?>