I am using saripaar for form validation. I have some edittext in fragmentA, on validation success , view will be switched to fragmentB.
Butterknife and saripaar annotation in fragment.
@NotEmpty
@BindView(R.id.nameEditText)
lateinit var nameEditText: EditText
Saripaar initialization:
val validator = Validator(this)
validator.setValidationListener(this)
To validate the fields:
validator.validate()
Validation is working fine for the first time. When come back from fragmentB to fragmentA, then validation is not working, it will directly call onvalidationsuccess.
On onValidationSucceeded , I am using following function to switch to fragmentB.
fun openFragment(fragment: Fragment) {
val ft = activity.supportFragmentManager.beginTransaction()
ft.replace(R.id.container, fragment)
ft.addToBackStack(null)
ft.commitAllowingStateLoss()
}
This problem only appears in kotlin but not in java.
I solved the issue, I have all the saripaar initialization in basefragment, I have the following code in basefragment with null check for validator instance:
if(validator==null){
validator = Validator(this)
validator.setValidationListener(this)
}
As I removed the null check part, now its working fine.
validator = Validator(this)
validator.setValidationListener(this)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With