From 95ccdfbd562e039e6ad4b16b14a541f77f4df87e Mon Sep 17 00:00:00 2001 From: balakz Date: Mon, 30 Aug 2021 01:17:47 +0200 Subject: [PATCH] FIX: validate inputs immediately --- .../formbuilderlibrary/element/EditTextElement.kt | 11 ++++++++++- .../formbuilderlibrary/element/LabelInputElement.kt | 11 ++++++++++- .../formbuilderlibrary/element/TextAreaElement.kt | 11 ++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/EditTextElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/EditTextElement.kt index e6bbe33..8f46c09 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/EditTextElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/EditTextElement.kt @@ -62,7 +62,7 @@ open class EditTextElement( editText?.addTextChangedListener(object : TextWatcher { override fun afterTextChanged(s: Editable) { if (validateImmediately) { - validate() + validation() } else { positiveValidation() } @@ -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() diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt index 7664eb9..a603a1b 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt @@ -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() } @@ -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() diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/TextAreaElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/TextAreaElement.kt index 5391f78..9396aef 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/TextAreaElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/TextAreaElement.kt @@ -95,7 +95,7 @@ class TextAreaElement( footerView?.text = "$length" } if (validateImmediately) { - validate() + validation() } else { positiveValidation() } @@ -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()