Saripaar formvalidation not working second time in kotlin
Asked Answered
U

1

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.

Unchurch answered 11/10, 2017 at 11:0 Comment(11)
Post related code.Iconium
@Iconium question updated with code.Unchurch
Where from are you performing validator.validate()? Post fragment/activity also.Iconium
There is a submit button in fragmentA, On submit button click, I have validate the form i.e validator.validate()Unchurch
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 ?Alisander
@RajeshDalsaniya Are you using with butterknife ? There is no error log or something like that. Can you share me buildtoolversion and support library version.Unchurch
There is also an open issue on the project, but it's not yet fixed. You can track it here [github.com/ragunathjawahar/android-saripaar/issues/204] (github.com/ragunathjawahar/android-saripaar/issues/204)Coprophilia
@Unchurch buildToolsVersion "26.0.2" and implementation 'com.mobsandgeeks:android-saripaar:2.0.3'Alisander
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 @Iconium @Rajesh @CoprophiliaUnchurch
Had you been generous enough and shared proper code - you'd have had solved your problem way sooner ;-)Iconium
Yes, stupid me. Thanks.Unchurch
U
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) 
Unchurch answered 17/10, 2017 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.