11

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.

captaindroid
  • 2,868
  • 6
  • 31
  • 45
  • Post related code. – azizbekian Oct 13 '17 at 16:20
  • @azizbekian question updated with code. – captaindroid Oct 15 '17 at 06:35
  • 1
    Where from are you performing `validator.validate()`? Post fragment/activity also. – azizbekian Oct 15 '17 at 07:47
  • There is a submit button in fragmentA, On submit button click, I have validate the form i.e `validator.validate()` – captaindroid Oct 15 '17 at 10:30
  • I am using saripaar with kotlin project and it working fine for me. I think in your project it should be reference problem because for fragments. Can you provide any log ? – Rajesh Dalsaniya Oct 15 '17 at 17:57
  • @RajeshDalsaniya Are you using with butterknife ? There is no error log or something like that. Can you share me buildtoolversion and support library version. – captaindroid Oct 16 '17 at 02:39
  • There is also an open issue on the project, but it's not yet fixed. You can track it here [https://github.com/ragunathjawahar/android-saripaar/issues/204] (https://github.com/ragunathjawahar/android-saripaar/issues/204) – Rinav Oct 16 '17 at 06:23
  • 1
    @captaindroid buildToolsVersion "26.0.2" and implementation 'com.mobsandgeeks:android-saripaar:2.0.3' – Rajesh Dalsaniya Oct 16 '17 at 07:25
  • I solved the issue, I have all the saripaar initialization in basefragment,I was checking the validator instance like: `if(validator==null){ validator = Validator(this) validator.setValidationListener(this) }` I removed the null check part and its now working. Thanks guys @azizbekian @Rajesh @Rinav – captaindroid Oct 17 '17 at 13:35
  • Had you been generous enough and shared proper code - you'd have had solved your problem way sooner ;-) – azizbekian Oct 17 '17 at 13:54
  • Yes, stupid me. Thanks. – captaindroid Oct 17 '17 at 14:19

1 Answers1

4

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) 
captaindroid
  • 2,868
  • 6
  • 31
  • 45