mukeshsolanki / android-otpview-pinview

A custom view to enter otp of different sizes used usually in cases of authentication.
MIT License
707 stars 207 forks source link

Text change listener for enabling and disabling button #108

Closed rmaming closed 4 years ago

rmaming commented 4 years ago

Subject of the issue

I was trying to enable and disable a button when the user completed the 6 digit input.

Steps to reproduce

I have a button that when the user completed the 6 digit pin should be enable but when it is less than the required pin length should be disable. Is there a way i can do this? I am looking for something like a text change listener?

Expected behaviour

Actual behaviour

rmaming commented 4 years ago

I tried using the onCompletionListener but somehow could not disable the button when the user decided to hit backspace or re-enter new pin

mukeshsolanki commented 4 years ago

I'm not entirely sure if the issue is related to the Lib? can you perhaps share a bit more details and also some code snippets of what you are trying to achieve?

rmaming commented 4 years ago

I want to detect every change in the OTP for example character remove. And I think the item in the pull request could solve my problem: Replace OnOtpCompletionListener with OnOtpTextChangeListener

When could this be available?

farhanafandi commented 4 years ago

Same problem here...

farhanafandi commented 4 years ago

Hey, I solve this problem with TextWatcher, try in your code bro

etOtp.addTextChangedListener(object : TextWatcher { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { if(count<=6){ btnSubmitOtp.isEnabled = false } } override fun beforeTextChanged(s: CharSequence,start: Int,count: Int,after: Int) {} override fun afterTextChanged(s: Editable) {} })

hope this can solve your problem too.

@rmaming

rmaming commented 4 years ago

Hey, I solve this problem with TextWatcher, try in your code bro

etOtp.addTextChangedListener(object : TextWatcher { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { if(count<=6){ btnSubmitOtp.isEnabled = false } } override fun beforeTextChanged(s: CharSequence,start: Int,count: Int,after: Int) {} override fun afterTextChanged(s: Editable) {} })

hope this can solve your problem too.

@rmaming

Thank you for this bro. I also this on the pull request: https://github.com/mukeshsolanki/android-otpview-pinview/pull/104. I guess this would also solve our problem.