maxkeppeler / sheets

⭐ ‎‎‎‏‏‎ ‎Offers a range of beautiful sheets (dialogs & bottom sheets) for quick use in your project. Includes many ways to customize sheets.
https://maxkeppeler.github.io/sheets/
Apache License 2.0
923 stars 77 forks source link

Input Bottom Sheet - Ability to disable positive button programatically #20

Closed russellbanks closed 3 years ago

russellbanks commented 3 years ago

Is your feature request related to a problem? Please describe. I've been migrating from Aiden Follestad's bottom sheets to this library and one thing I was able to do from that was if an input is incorrect, I could disable the positive button. For example, I need to ensure in my app that the input does not contain the characters "//". I had achieved this previously by doing: if input.contains("//") { dialog.getActionButton(WhichButton.POSITIVE).isEnabled = false }

Describe the solution you'd like The ability to disable the positive button programatically

maxkeppeler commented 3 years ago

The Issue is requesting basically the same as the issue #21 if I see that correctly. I don't think it's necessary to allow disabling / hiding the positive button, but to define if the current input is valid. If it is valid, alongside all the other inputs, the positive button will be displayed, or when not it won't be displayed.

fun isInputValid(inputText: String): Boolean {
 return inputText.contains("//") // if true, positive button will be displayed, otherwise not.
}

Would this work how you imagine it? For custom bottom sheet implementations, the visibility of the buttons can be changed. But I think it would be easier if developers could just specify the validation logic & hint/ error messages if it's not valid. Let me know your opinion!

russellbanks commented 3 years ago

This functionality to verify an input would be perfect, thank you!

maxkeppeler commented 3 years ago

With the coming version, check the sample setup - I added a password example with the InputSheet with custom validation logic. That's how it will look.

InputSheet().show(this) {
            ...
            with(InputEditText {
                ...
                endIconMode(TextInputLayout.END_ICON_PASSWORD_TOGGLE)
                passwordVisible(false /* Don't display password in clear text. */)
                validationListener { value ->
                    val valid = <Add custom validation logic>
                    if (valid) Validation.success()
                    else Validation.failed("Custom error text")
                }
                ...
            })
            ...
}