throrin19 / android-validator Goto Github PK
View Code? Open in Web Editor NEWForm Validator Library for Android
Form Validator Library for Android
Hello, I recently downloaded the library, and using it I found that the validation is sequential, so if I have 6 fields and 5 are erroneous but the latter is correct, then the validation will return true.
I took the liberty to fix the error I leave the code:
Class Form:
public boolean validate(){
boolean result = true;
int validator = 0;
Iterator<AbstractValidate> it = this._validates.iterator();
while(it.hasNext()){
AbstractValidate validate = it.next();
result = validate.isValid();
if (result == false){
validator++;
}
}
if (validator > 0){
result = false;
}
return result;
}
Thank you very much,
Andres Bocanumenth
Great library for easy form validation in Android, but I have a concern about potential memory leak in AbstractValidator class.
protected Context mContext;
public AbstractValidator(Context c) {
mContext = c;
}
I found out that this Context reference, if instantiated inside a Fragment that setRetainInstance == true, well retain a reference to the first activity passed in constructor.
AFAIK, according to Android Activity lifecycle, when there's configuration change, e.g when user change display orientation, an Activity will be destroyed and recreated. But a setRetainInstance == true fragment, will not be recreated on a configuration change.
So, in the end of Activity recreation, my retained fragment still hold a reference to the previously 'destroyed' Activity context, which is certainly a memory leak. CMIIW
I would like to contribute in this library, planning to have a pull request of my suggested implementation within this week :)
In the program that I'm coding, I have a sliding layer. When the validator checks and sees that the form isnt complete, it shows the error.
My problem is that the error pops up over the sliding layer when i slide it from the side but the textview is still under it under it.
Is there a way i can change the z index of it?
For the classes ConfirmValidate and OrTwoRequiredValidate it looks like the isValid method should take a String object and not Object. This is an issue after changing the two classes to extend the abstract classes.
When I create an instance of any type of Validator, for example, NotEmptyValidator, there always be an error with detailedMessage "Failed resolution of: Lcom/throrinstudio/android/example/validator/R$string;".
My source code is following:
NotEmptyValidator notEmptyValidator = new NotEmptyValidator(fragment.getContext());
And the cause info of this error is:
java.lang.ClassNotFoundException: Didn't find class "com.throrinstudio.android.example.validator.R$string" on path: DexPathList[[zip file "/data/app/com.fourthdimension.gaodingv1android-2/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
Wanted to know if we can add validation to disabled field. For example an EditText which is filled by output of DatePicker dialog. The DatePicker is enabled on tap of a button.
....the form can just handle the EditText.
Just wondering what other objects did you want to validate. I wanted to try coding it
Have you thought about adding Gradle?
Hi,
First of all, thanks for your great jobs.
It's works great as an Android project.
But, I have a problem when I want to use it as a library. Form displays error bubbles (at the right place) but there is no text in bubbles.
I try with preset validator (NotEmptyValidator) with en-US, en-GB but still no message.
There is a screenshot of my app : http://goo.gl/Vu0fj
I put your string ressources in my main project but always the same problem.
Did you ever got this issue ? and managed it ?
function closeAllErrors() cant close ConfirmValidate. You'll get exception
E/AndroidRuntime(27795): java.lang.ClassCastException: >.validator.validate.ConfirmValidate cannot be cast to .validator.Validate
Hi,
I looked at the code for form validation and it looks like the following:
/**
* Called to validate our form.
* If an error is found, it will be displayed in the corresponding field.
*
* @return boolean true if the form is valid, otherwise false
*/
public boolean validate() {
boolean formValid = true;
for (AbstractValidate validate : mValidates) {
// Form is invalid if only one of the validates is false (alternation rule)
formValid = formValid || validate.isValid();
}
return formValid;
}
since formValid = true from the start, it will always remain true, since
x = (true || false) = true
and
x = (true || true) = true.
So basically, the form always validates to true.
Am I missing something? :(
I think the OR should be replaced with AND...
Found a potential bug, if you have an EditText in a scrollview at the top of the view and you scroll the page down so that the EditText has scrolled off the view at the top, The validator message scrolls through the action bar covering the action bar
Hi,
In the class "RangeValidator", there is a static class variable called "mErrorMessage".
It shouldn't be static as if you have multiple "RangeValidator", it will only keep the last value.
In my case i had 3 RangeValidator and the same message was displayed three times. Removing "static" modifier fix the issue.
Actually, i'm also wondering why "getMessage" is overrided in "RangeValidator" while it is not in others validators. :)
Regards,
Clément.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.