inmite / android-validation-komensky

A simple library for validating user input in forms using annotations.
Apache License 2.0
508 stars 78 forks source link

FormValidator.validateSingleView() is not working as expected #44

Open joomsite opened 7 years ago

joomsite commented 7 years ago

ValidationKomensky is fantastic Validator but there are 2 issues which put me off.

Issue 1 : FormValidator.validateSingleView() is not working as expected.

For Example,

I have following 3 validations on my form.

@NotEmpty(messageId = R.string.validation_vehicle_registration,order = 1) EditText vehicleNoEditText;

@NotEmpty(messageId = R.string.validation_puc_number) EditText pucNoEditText;

@DateInFuture(datePattern = "dd-MM-yyyy",allowToday = true, messageId = R.string.validation_date_in_future) EditText pucEndDateEditText;

vehicleNoEditText is Mandatory but pucNoEditText & pucEndDateEditText are Non mandatory.

I want to validate pucNoEditText only if pucEndDateEditText is updated.

I implement this validation as below.

if(!FormValidator.validateSingleView(this, vehicleNoEditText, simpleCallback)){ isValid = false; }

if(!StringUtils.isEmpty(pucEndDateEditText.getText().toString())){ if(FormValidator.validateSingleView(this, pucEndDateEditText, simpleCallback)){ isValid =false; } if(FormValidator.validateSingleView(this, pucNoEditText, simpleCallback)){ isValid =false; }

}

Issue is FormValidator.validateSingleView(this, vehicleNoEditText, simpleCallback)- Not only validate vehicleNoEditText but all the validations declared in the Activities. This also validate pucNoEditText & pucEndDateEditText.( which I don't want to validate with vehicleNoEditText, I have separate validation call for them)

FormValidator.validateSingleView(Object target, View formContainer, View targetView, Map<view, fieldinfo=""> infoMap, IValidationCallback callback) - evaluate Single View then also validate all the other declared validations and returns false. This is worse as no error shown against the others but I can't submit Form as well.

Narayane commented 7 years ago

Hi @joomsite ,

I have made a pull request #46 to solve this issue :)