https://github.com/devscast/validable
An easy-to-use text field validator supporting Compose. Multiplatform
https://github.com/devscast/validable
android cmp compose-multiplatform jetpack-compose kmp kotlin kotlin-library kotlin-multiplatform
Last synced: about 2 months ago
JSON representation
An easy-to-use text field validator supporting Compose. Multiplatform
- Host: GitHub
- URL: https://github.com/devscast/validable
- Owner: devscast
- License: other
- Created: 2021-11-30T20:12:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-17T00:22:18.000Z (2 months ago)
- Last Synced: 2025-03-02T09:11:51.596Z (2 months ago)
- Topics: android, cmp, compose-multiplatform, jetpack-compose, kmp, kotlin, kotlin-library, kotlin-multiplatform
- Language: Kotlin
- Homepage: https://devscast.github.io/validable/
- Size: 990 KB
- Stars: 71
- Watchers: 0
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# validable

[](https://github.com/devscast/validable/actions/workflows/build.yaml)Validable is an extensible library that simplifies text field validation for Jetpack Compose and
Compose Multiplatform by providing abstraction and reusable validation logic.This is what it looks like :
```kotlin
@Composable
fun MyScreen() {val emailField = remember { EmailValidable() }
// pass all fields to the withValidable method
val validator = rememberValidator(emailField)TextField(
value = emailField.value,
onValueChange = { emailField.value = it }, // update the text
isError = emailField.hasError(), // check if the field is not valid
)AnimatedVisibility(visible = emailField.hasError()) {
Text(
text = emailField.errorMessage ?: "",
modifier = Modifier.fillMaxWidth(),
style = LocalTextStyle.current.copy(color = MaterialTheme.colors.error)
)}
Button(
// a state to check if all fields are valid, without submitting the form
enabled = validator.isValid,
onClick = {
validator.validate {
// will be executed if all fields are valid
Toast.makeText(context, "All fields are valid", Toast.LENGTH_SHORT).show()
}
}
) {
Text(text = "Submit")
}
}
```## Gradle setup
Include the **validable** dependency in your module `build.gradle` or `build.gradle.kts` :
```kotlin
dependencies {
implementation("tech.devscast:validable:")
}
```The latest version
is ## For full documentation, check out [https://devscast.github.io/validable](https://devscast.github.io/validable)
## Contributing
We'd love contributions !
We will also try to tag any issues on
our [issue tracker](https://github.com/devscast/validable/issues) that we'd love help with, so
if you just want to dip in, go have a look.If you do want to contribute to this project, we have a [code of conduct](CODE_OF_CONDUCT.md).