A form validation library for android jetpack compose
- Determine Validation Flow. Flow.Down|Flow.Up|Flow.Splash
- Custom Validation
- Validation Snackbar
- Validation State Callbacks
- Library is well documented
device-2022-01-15-014026.mp4
@Composable
fun ScreenContent() {
var name by remember { mutableStateOf("") }
var nameError by remember { mutableStateOf<String?>(null) }
var email by remember { mutableStateOf("") }
var emailError by remember { mutableStateOf<String?>(null) }
val nameField = "Name"
val emailField = "Email"
val validator = FormValidator(
fields = listOf(
ValidationField(
value = name,
name = nameField,
onError = {
nameError = it
}),
ValidationField(
value = email,
onError = {
emailError = it
}, type = FormValidator.Type.Email
)
)
)
Form(
validator = validator,
modifier = Modifier
.fillMaxSize()
.verticalScroll(state = rememberScrollState())
.padding(16.dp)
) {
Spacer(modifier = Modifier.height(30.dp))
AppTextField(
label = nameField,
value = name,
placeholder = "Enter name",
onValueChanged = { name = it },
errorMessage = nameError
)
Spacer(modifier = Modifier.height(16.dp))
AppTextField(
label = emailField,
value = email,
placeholder = "Enter email",
onValueChanged = { email = it },
errorMessage = emailError,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email)
)
Spacer(modifier = Modifier.height(40.dp))
AppButton(text = "Submit") {
if(validator.validate())
showToast(validator.errorMessage)
}
}
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.funyin:FormValidator:1.0.0'
}