Closed molexx closed 6 years ago
Hi @molexx, you can use validator passing a view (or a list of views) as parameter, validate(view). It's mean that only that view will be validate.
So you can combine text or focus listeners to make the best logic for your case.
I faced the same problem some time ago and I decided to use RxBinding (https://github.com/JakeWharton/RxBinding) which allows me to know when user stop to type, so I could validate it separately. Other way is set Observables to listen more than one fields per time, and validate them together.
Thanks for the suggestion.
I want to run the validation as the user types (using a TextWatcher) so that the submit button can become enabled as soon as the user finishes typing their email address without them having to tap outside the EditText.
That TextWatcher can call validate(et) passing the EditText they're typing in but when they type the first character the validation will fail and set the error text... too early IMHO.
You can do some stuffs to avoid this. First you can put a condition with a minimum number of characters in the listener until run the validation. Or if you are using RxBinding, you can set a debounce, it's mean that it wait a period of time until run the code inside the listener (or you can try to implement this in the TextWatcher too).
Those would cause at least one of the these UX undesirables:
The submit button doesn't become enabled because the user's email address is shorter than n characters or the user has to wait x seconds after finishing typing
The error text appears when the user has typed n characters of their email address even though they haven't finished typing it yet, or the user pauses during entry
When I faced this problem I put a listener in the password field with the condition email not empty before ran the validator code, and then if it pass I enable the button.
I don't know what you really want, but you should consider only calls validation code when the user type the password (with some condition), or other stuff to deal with your business logic.
What I'm trying to say is that this kind of problems are part of your logic and I don't understand what you sugest to include in the validator lib.
Validating after the user has typed the first character will immediately show the field's error message which is abrasive to the user who hasn't had a chance yet.
My logic would like to define whether or not an error message is shown but I cannot see a parameter within the library to allow it to do that.
Maybe there could be a parameter on each EditText named something like 'showErrorMessage'? It should default to true for compatibility.
My logic would initially set that to false and then set it to true from an onFocusListener when the user leaves the field.
I'm closing this issue because it has been inactive for a long time. Please reopen if you still want to discuss.
I want to run validation so that the submit button can be disabled until all the fields are valid. But calling validate() causes the error text to appear on the fields before the user has even had a chance to type anything in them which is a harsh UX.
An OnFocusChangeListener on each field could set whether the error message is shown or not, but I don't see an option/property to set for that?