Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
yveskalume committed Jan 27, 2025
1 parent bd0f9d3 commit 6b8b592
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,75 @@
![Maven Central Version](https://img.shields.io/maven-central/v/tech.devscast/validable?color=blue)
[![build](https://github.com/devscast/validable/actions/workflows/build.yaml/badge.svg)](https://github.com/devscast/validable/actions/workflows/build.yaml)

Validable is an extensible library that simplifies text field validation for Jetpack Compose by providing abstraction and reusable validation logic.
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 :

<img src="screenshots/inputscreen.png?raw=true" width="459" alt="Welcome screen">

```kotlin
@Composable
fun MyScreen() {
val emailField = remember { EmailValidable() }
@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(
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 {
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")
}
) {
Text(text = "Submit")
}
}
```

## Gradle setup

Include the **validable** dependency in your module `build.gradle` or `build.gradle.kts` :


```kotlin
dependencies {
implementation("tech.devscast:validable:<version>")
}
```

The latest version is ![Maven Central Version](https://img.shields.io/maven-central/v/tech.devscast/validable?color=blue)
The latest version
is ![Maven Central Version](https://img.shields.io/maven-central/v/tech.devscast/validable?color=blue)

## 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
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).

0 comments on commit 6b8b592

Please sign in to comment.