FormHandler

class FormHandler(formSchemaBuilder: FormSchemaBuilder, val formDataManager: FormDataManager, val formValidator: FormValidator = FormValidator(), val payload: Map<String, Any?> = emptyMap(), val handlerScope: CoroutineScope = CoroutineScope(SupervisorJob() + OctaviusDispatchers.Virtual)) : FormActionTrigger

Handles the form's lifecycle - the main coordinator of the form system.

FormHandler coordinates all form components:

  • FormSchema - the structure and controls of the form

  • FormState - reactive state of all controls

  • FormDataManager - loading data from the database and processing results

  • FormValidator - field and business-rule validation

Lifecycle:

  1. Initialize the components and wire references between them

  2. Load data (editing) or set default values (new record)

  3. Handle user actions (validation + running the action)

The handler knows nothing about navigation or about what happens after an action - it only returns true/false from triggerAction. The decision "saving closes the screen" is made by the button's lambda in the schema builder.

Parameters

formSchemaBuilder

Builder providing the form's structure.

formDataManager

Manager responsible for data operations.

formValidator

Validator checking the data.

payload

Additional data passed to the form (e.g. a parent ID).

handlerScope

CoroutineScope for asynchronous operations.

Constructors

Link copied to clipboard
constructor(formSchemaBuilder: FormSchemaBuilder, formDataManager: FormDataManager, formValidator: FormValidator = FormValidator(), payload: Map<String, Any?> = emptyMap(), handlerScope: CoroutineScope = CoroutineScope(SupervisorJob() + OctaviusDispatchers.Virtual))

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
private val formSchema: FormSchema
Link copied to clipboard
private val formState: FormState
Link copied to clipboard
Link copied to clipboard
private val handlerScope: CoroutineScope
Link copied to clipboard
Link copied to clipboard
private val payload: Map<String, Any?>

Functions

Link copied to clipboard
Link copied to clipboard

API for FormView - access to the form components

Link copied to clipboard
internal fun getControl(name: String): Control<*>?
Link copied to clipboard
internal fun getControlState(name: String): ControlState<*>?
Link copied to clipboard

Sets the form component references on all controls.

Link copied to clipboard
private fun loadData()

Asynchronously fetches the initial values from FormDataManager.initData (in handlerScope) and creates the control states from them.

Link copied to clipboard
open suspend override fun triggerAction(actionKey: String, validates: Boolean): Boolean

Runs the whole action: validation, collecting the form data, executing the action.

Link copied to clipboard
private fun validatedFormData(actionKey: String, validates: Boolean): FormResultData?

Collects the form data if it passes validation, or returns null when one of the stages failed it. The stage itself records the errors to show, in errorManager.