FormValidator
Declarative form validation for Jetpack Compose — Android, JVM, and iOS.
FormValidator lets you define validation rules alongside your fields, then call validate() once on submit. Errors flow back to each field via callbacks, and the ErrorSafe pattern keeps value, error, and dirty-state in a single remember-able unit.
implementation("com.github.funyin:FormValidator:LIBRARY_VERSION")
implementation 'com.github.funyin:FormValidator:LIBRARY_VERSION'
Latest version
Find the current release on the releases page.
At a glance
val validator = FormValidator(
flow = FormValidator.Flow.Down,
fields = listOf(
ValidationField(value = email.value, name = "Email", type = FormValidator.Type.Email) {
email = email.copy(error = it)
}
)
)
Form(validator) {
AppTextField(
label = "Email",
value = email.value,
onChange = { email = email.copy(value = it) },
errorMessage = email.error
)
Button(onClick = { if (validator.validate()) submit() }) {
Text("Submit")
}
}
// Live validation as the user types
LaunchedEffect(email.value) { validator.validate() }
// Gate submit
Button(
enabled = validator.valid,
onClick = { validator.validate(); submit() }
) { Text("Submit") }