adding extension for acting on textinputlayout text changes
This commit is contained in:
parent
a02141c7c2
commit
ffb8b10f66
@ -44,11 +44,18 @@ fun TextInputLayout.content() = editText().text.toString()
|
|||||||
fun TextInputLayout.hasContent() = !editText().text.isNullOrEmpty()
|
fun TextInputLayout.hasContent() = !editText().text.isNullOrEmpty()
|
||||||
|
|
||||||
fun TextInputLayout.clearErrorOnChange(lifecycleOwner: LifecycleOwner) {
|
fun TextInputLayout.clearErrorOnChange(lifecycleOwner: LifecycleOwner) {
|
||||||
editText().textChanges()
|
editText()
|
||||||
|
.textChanges()
|
||||||
.onEach { error = null }
|
.onEach { error = null }
|
||||||
.launchIn(lifecycleOwner.lifecycleScope)
|
.launchIn(lifecycleOwner.lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun TextInputLayout.onTextChange(lifecycleOwner: LifecycleOwner, action: (CharSequence) -> Unit) {
|
||||||
|
editText().textChanges()
|
||||||
|
.onEach(action)
|
||||||
|
.launchIn(lifecycleOwner.lifecycleScope)
|
||||||
|
}
|
||||||
|
|
||||||
fun TextInputLayout.associateContentStateWith(button: View, enabledPredicate: (String) -> Boolean = { it.isNotEmpty() }) {
|
fun TextInputLayout.associateContentStateWith(button: View, enabledPredicate: (String) -> Boolean = { it.isNotEmpty() }) {
|
||||||
button.isEnabled = enabledPredicate(content())
|
button.isEnabled = enabledPredicate(content())
|
||||||
editText().addTextChangedListener(object : SimpleTextWatcher() {
|
editText().addTextChangedListener(object : SimpleTextWatcher() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user