Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/funyin/formvalidator

A form validation library for android jetpack compose
https://github.com/funyin/formvalidator

jetpack-compose validation-library

Last synced: about 2 months ago
JSON representation

A form validation library for android jetpack compose

Awesome Lists containing this project

README

        

# FormValidator [![](https://jitpack.io/v/funyin/FormValidator.svg)](https://jitpack.io/#funyin/FormValidator) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-FormValidator-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/8353) [![Made in Nigeria](https://img.shields.io/badge/made%20in-nigeria-008751.svg?style=flat-square)](https://github.com/acekyd/made-in-nigeria)
A form validation library for android jetpack compose

## Features
- Determine Validation Flow.
__Flow.Down__|__Flow.Up__|__Flow.Splash__
- Custom Validation
- Validation Snackbar
- Validation State Callbacks
- Library is well documented

## Preview

https://user-images.githubusercontent.com/38915569/149603789-1f47436b-b8f9-44a6-98a6-6ec389a75e7b.mp4

## Example
```kotlin
@Composable
fun ScreenContent() {
var name by remember { mutableStateOf("") }
var nameError by remember { mutableStateOf(null) }
var email by remember { mutableStateOf("") }
var emailError by remember { mutableStateOf(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)
}
}
}
```

## Getting started
### Step 1. Add the JitPack repository to your build file
```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

### Step 2. Add the dependency
```gradle
dependencies {
implementation 'com.github.funyin:FormValidator:1.0.0'
}
```

[![BuyMeAShawrma.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1619907239535/KqJOyu-70.png)](https://www.buymeacoffee.com/funyinkash)