Skip to content

Commit

Permalink
explain how to create a custom validable
Browse files Browse the repository at this point in the history
  • Loading branch information
yveskalume committed Jun 25, 2024
1 parent 5f377a8 commit 05b8a16
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
![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)

Validating text fields when using jetpack compose can sometimes be challenging and verbose.

Validable is an extensible library that allows you to validate your text fields in a simpler way while having a reusable code.
Validable is an extensible library that simplifies text field validation for Jetpack Compose by providing abstraction and reusable validation logic.

This is what it looks like :

Expand Down
21 changes: 21 additions & 0 deletions docs/create_validable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Create a validable

You can create a validable with a custom validation logic.

All you need to do is to extend the `BaseValidable` class, which takes two functions as parameters:

- `validator`: This function checks if the value meets a specified condition and returns a boolean.
- `errorFor`: Is called when the value does not meet the condition and returns a string as the error message.

Let's see an example of a custom validable that checks if an input contains the word "devscast"

```kotlin
class DevscastValidable : BaseValidable(
validator = { value ->
value.contains("devscast", ignoreCase = true)
},
errorFor = { value ->
"$value does not contain the word 'devscast'."
}
)
```
4 changes: 1 addition & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
![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)

Validating text fields when using jetpack compose can sometimes be challenging and verbose.

Validable is an extensible library that allows you to validate your text fields in a simpler way while having a reusable code.
Validable is an extensible library that simplifies text field validation for Jetpack Compose by providing abstraction and reusable validation logic.

```kotlin
@Composable
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ markdown_extensions:

nav:
- 'Get Started': index.md
- 'Create a validable': create_validable.md
- 'Built in validables':
- 'CardSchemeValidable' : validables/cardscheme.md
- 'Email' : validables/email.md
Expand Down

0 comments on commit 05b8a16

Please sign in to comment.