Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ By default, the library prompts error messages and doens't dismiss the error aut
app:validateDateAutoDismiss="@{true}" />
```

### Hiding validation messages ###

If you want to check if fields are valid but not have the EditText's error message set, add an attribute:
```
app:showErrorMessage='@{false}'
```
This is useful if you're validating as the user types to enable a button - showing an error after the user has only typed one character is not an ideal user experience. You can use the databinding expression to show the message according to your requirements, such as after onFocusChanged when the user navigates out of the field.


## License ##

Copyright 2017-present Ilhasoft
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package br.com.ilhasoft.support.validation.binding;

import android.databinding.BindingAdapter;
import android.widget.TextView;

import br.com.ilhasoft.support.validation.R;

/**
* Bindings for properties which configure validation behaviour
*
*
* Created by molexx on 12/11/2017.
*/
public class ConfigBindings {

@BindingAdapter(value = {"showErrorMessage"}, requireAll = false)
public static void bindingShowErrorMessage(TextView view, boolean showErrorMessage) {
if (showErrorMessage == false) {
view.setTag(R.id.show_error_message, Boolean.FALSE);
} else {
view.setTag(R.id.show_error_message, null);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ public static void removeError(TextView textView) {
}

public static void setError(TextView textView, String errorMessage) {
TextInputLayout textInputLayout = getTextInputLayout(textView);
if (textInputLayout != null) {
textInputLayout.setErrorEnabled(!TextUtils.isEmpty(errorMessage));
textInputLayout.setError(errorMessage);
} else {
textView.setError(errorMessage);
Boolean b = (Boolean)textView.getTag(R.id.show_error_message);
if (!Boolean.FALSE.equals(b)) {
TextInputLayout textInputLayout = getTextInputLayout(textView);
if (textInputLayout != null) {
if ((TextUtils.isEmpty(errorMessage) && !TextUtils.isEmpty(textInputLayout.getError())) || (errorMessage != null && !errorMessage.equals(textInputLayout.getError()))) {
textInputLayout.setError(errorMessage);
}
} else {
if ((TextUtils.isEmpty(errorMessage) && !TextUtils.isEmpty(textView.getError())) || (errorMessage != null && !errorMessage.equals(textView.getError()))) {
textView.setError(errorMessage);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<item type="id" name="validator_rule" />
<item type="id" name="text_watcher_clear_error" />
<item type="id" name="show_error_message" />
</resources>