FieldTypeAdapter

interface FieldTypeAdapter<V, S, U>(source)

An adapter interface for converting between different type representations of a field value.

This interface enables type conversion between:

  • V: The stored value type in the form data

  • S: The validation target type (what validators operate on)

  • U: The input/display type (what the UI components work with)

This is useful when you need to validate or display a field value in a different format than how it's stored. For example, storing an integer but displaying it as a string in a text field.

Usage:

class IntStringAdapter : FieldTypeAdapter<Int, String, String> {
override fun toValidationTarget(value: Int): String = value.toString()
override fun toInput(value: Int): String = value.toString()
override fun fromInput(value: String, current: Int): Int = value.toIntOrNull() ?: current
}

Parameters

V

The type of the value as stored in the form data.

S

The type used for validation.

U

The type used for input/display in UI components.

Inheritors

Functions

Link copied to clipboard
abstract fun fromInput(value: U, current: V): V

Converts the input/display value back to the stored value type.

Link copied to clipboard
abstract fun toInput(value: V): U

Converts the stored value to the input/display type.

Link copied to clipboard
abstract fun toValidationTarget(value: V): S

Converts the stored value to the validation target type.