Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Commit

Permalink
0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
afollestad committed Apr 6, 2019
1 parent 0285af1 commit bbdb11a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
42 changes: 35 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
7. [Submit With](#submit-with)
8. [Conditionals](#conditionals)
9. [Supporting Additional Views](#supporting-additional-views)
10. [Real Time Validation](#real-time-validation)

---

Expand All @@ -37,7 +38,7 @@ Add this to your module's `build.gradle` file:
```gradle
dependencies {
implementation 'com.afollestad:vvalidator:0.3.2'
implementation 'com.afollestad:vvalidator:0.4.0'
}
```

Expand All @@ -58,7 +59,6 @@ class MyActivity : AppCompatActivity() {
input(R.id.your_edit_text) {
isNotEmpty()
}

submitWith(R.id.submit) { result ->
// this block is only called if form is valid.
// do something with a valid form state.
Expand Down Expand Up @@ -168,7 +168,6 @@ form {
checkable(R.id.view_id, name = "Optional Name") {
isChecked()
isNotChecked()

// Custom assertions
assert("expected something") { view -> true }
}
Expand All @@ -188,7 +187,6 @@ form {
selection().atMost(1)
selection().atLeast(1)
selection().greaterThan(1)

// Custom assertions
assert("expected something") { view -> true }
}
Expand All @@ -208,7 +206,6 @@ form {
progress().atMost(1)
progress().atLeast(1)
progress().greaterThan(1)

// Custom assertions
assert("expected something") { view -> true }
}
Expand All @@ -230,7 +227,6 @@ form {
input(R.id.some_input) {
isNotEmpty().description("Please enter a value!")
}

spinner(R.id.some_spinner) {
selection()
.greaterThan(0)
Expand Down Expand Up @@ -305,7 +301,6 @@ error hook for each field that you can use to display errors in the UI.
form {
checkable(R.id.view_id, name = "Optional Name") {
isChecked()

onErrors { view, errors ->
// `view` here is a CompoundButton.
// `errors` here is a List<FieldError>, which can be empty to notify that there are no longer
Expand Down Expand Up @@ -437,6 +432,13 @@ class MyField(
value = currentValue
)
}

override fun startRealTimeValidation(debounce: Int) {
// See the "Real Time Validation" section below.
// You'd want to begin observing input to the view this field attaches to,
// and call `validate()` on this field when it changes. You should respect the
// `debounce` parameter as well.
}
}
```

Expand Down Expand Up @@ -480,3 +482,29 @@ form {

When the form is validated, your assertion's `isValid(MyView)` method is executed. If it returns
false, this view is marked as erroneous in the validation results.

---

## Real Time Validation

This library provides an option to support real time validation. Rather than performing validation
when you call `validate()` on the `Form`, or `validate()` on an individual field, the library
makes these calls for you as the view's change.

```kotlin
form {
useRealTimeValidation()
input(R.id.your_edit_text) {
isNotEmpty()
}
}
```

With this example above, the form will automatically perform validation when the input field's
text changes. *Note that this does work with all field types, not just input fields.*

`useRealTimeValidation()` has an optional `Int` parameter that lets you set a custom debounce delay.
This delay is how much of a gap there is between a field's value changing and validation being
performed. This prevents too many validations from occurring in a row, like as a user is typing in
an input field - you wouldn't want to validate with every single letter input. *The default value
is 500 (milliseconds), or a half second.*
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.4.0

Real time validation capabilities; allows you to perform validation as views are changing in real
time, like the text of an input field. Checkout the README for details.
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ ext.versions = [
minSdk : 16,
compileSdk : 28,
buildTools : '28.0.3',
publishVersion : '0.3.2',
publishVersionCode : 16,
publishVersion : '0.4.0',
publishVersionCode : 17,

// Plugins
gradlePlugin : '3.3.2',
Expand Down

0 comments on commit bbdb11a

Please sign in to comment.