Skip to content

Commit

Permalink
FIX: validate inputs immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
balakz committed Aug 29, 2021
1 parent 538aa84 commit 95ccdfb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ open class EditTextElement(
editText?.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {
if (validateImmediately) {
validate()
validation()
} else {
positiveValidation()
}
Expand All @@ -79,6 +79,15 @@ open class EditTextElement(
return view
}

private fun validation() {
try {
super.validate()
textInputLayout?.error = null
} catch (e: ValidationException) {
textInputLayout?.error = e.message
}
}

private fun positiveValidation() {
try {
super.validate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class LabelInputElement(
object : TextWatcher {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (validateImmediately) {
validate()
validation()
} else {
positiveValidation()
}
Expand Down Expand Up @@ -116,6 +116,15 @@ class LabelInputElement(
textInputEditText?.setText(text)
}

private fun validation() {
try {
super.validate()
textInputLayout?.error = null
} catch (e: ValidationException) {
textInputLayout?.error = e.message
}
}

private fun positiveValidation() {
try {
super.validate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TextAreaElement(
footerView?.text = "$length"
}
if (validateImmediately) {
validate()
validation()
} else {
positiveValidation()
}
Expand Down Expand Up @@ -154,6 +154,15 @@ class TextAreaElement(
}
}

private fun validation() {
try {
super.validate()
textInputLayout?.error = null
} catch (e: ValidationException) {
textInputLayout?.error = e.message
}
}

override fun validate() {
try {
super.validate()
Expand Down

0 comments on commit 95ccdfb

Please sign in to comment.