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.
validator.validate()
? Post fragment/activity also. – Iconiumvalidator.validate()
– Unchurchif(validator==null){ validator = Validator(this) validator.setValidationListener(this) }
I removed the null check part and its now working. Thanks guys @Iconium @Rajesh @Coprophilia – Unchurch