Input

sealed interface Input

A user input. An input can have 3 states:

  • Invalid: input contains validation errors listed in the Input.Invalid.errors field.

  • Valid: an input that has been validated and is considered valid

  • Empty: an input that has either a default value, an empty value, or has never been validated. How you want to handle Empty values depends on the business logic of your app.

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
value class Empty : Input

An input that has either a default value, an empty value, or has never been validated. How you want to handle Empty values depends on the business logic of your app.

Link copied to clipboard
data class Invalid : Input

A value that signifies an invalid input

Link copied to clipboard
value class Valid : Input

A valid input.

Properties

Link copied to clipboard

Whether this is Input.Empty

Link copied to clipboard

Whether the actual string of this Input is blank

Link copied to clipboard

Whether this is Input.Invalid

Link copied to clipboard

Whether this is Input.Valid

Link copied to clipboard

Whether this Input is valid or empty

Link copied to clipboard
abstract val value: String

A current string value that the input holds

Functions

Link copied to clipboard
open fun copy(value: String = this.value): Input

Copy the input. Type and errors are preserved

Link copied to clipboard
infix fun Input.mustMatch(other: Input): Input

Applies an additional Rules.Equals to this input, then appends the result of the validation to other validation errors present, if any. Allows to create an Input that must always match some other one Don't forget to run the validation on both the dependent and the original inputs when any of them changes.

Link copied to clipboard

Returns Input.value if it is valid, otherwise an empty string

Link copied to clipboard

Returns Input.value if it is valid, otherwise null

Link copied to clipboard
fun Input.validate(form: Form): Input

Validate this Input using a given form.

fun Input.validate(rule: Rule): Input

Validate this Input using the given rule. Previous errors are preserved.

Link copied to clipboard

Returns null if this Input is not valid, otherwise returns Input.value