FormValidator

class FormValidator<T>(formSchema: Schema<T>, externalValidations: ExternalValidations = emptyMap())(source)

Class used to validate form values. Form values are of type T and represent the content of a form with the provided form schema.

External validations may be provided to further validate the form against validations not present in the schema.

Once instantiated with a given form schema, the validator can be used to validate values according to all validations of said schema, as well as the validator's external validations.

Constructors

Link copied to clipboard
constructor(formSchema: Schema<T>, externalValidations: ExternalValidations = emptyMap())

Functions

Link copied to clipboard
suspend fun isValid(formValue: T, externalContexts: ExternalContexts? = null, runCriteria: ValidateRunCriteria = ValidateRunCriteria.ExternalIfInternalValid): Boolean

Returns whether all parts of the form value formValue are valid according to their schemas. These parts are said to be valid if they contain no validation errors.

suspend fun isValid(formValue: T, path: String, externalContexts: ExternalContexts? = null, runCriteria: ValidateRunCriteria = ValidateRunCriteria.ExternalIfInternalValid): Boolean
suspend fun isValid(formValue: T, path: Path, externalContexts: ExternalContexts? = null, runCriteria: ValidateRunCriteria = ValidateRunCriteria.ExternalIfInternalValid): Boolean

Returns whether the parts of the form value formValue matching path are valid according to their schemas. These parts are said to be valid if they contain no validation errors.

Link copied to clipboard
fun validate(formValue: T, externalContexts: ExternalContexts? = null, runCriteria: ValidateRunCriteria = ValidateRunCriteria.ExternalIfInternalValid): Flow<LocatedValidationIssue>

Validates all parts of the form value formValue against the validator's schema. Returns a flow of found validation issues.

fun validate(formValue: T, path: String, externalContexts: ExternalContexts? = null, runCriteria: ValidateRunCriteria = ValidateRunCriteria.ExternalIfInternalValid): Flow<LocatedValidationIssue>
fun validate(formValue: T, path: Path, externalContexts: ExternalContexts? = null, runCriteria: ValidateRunCriteria = ValidateRunCriteria.ExternalIfInternalValid): Flow<LocatedValidationIssue>

Validates the parts of the form value formValue matching path against the validator's schema. Returns a flow of found validation issues.