Created
January 22, 2019 01:06
-
-
Save weverb2/500feb2af846c9ec2c57ea3694a70ad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainViewModel : ViewModel() { | |
private val _isFormValid = MutableLiveData<Boolean>() | |
val isFormValid: LiveData<Boolean> | |
get() = _isFormValid | |
var username = "" | |
set(value) { | |
field = value | |
validateForm() | |
} | |
var password = "" | |
set(value) { | |
field = value | |
validateForm() | |
} | |
private fun validateForm() { | |
if (username.length > 8 && password.length > 8) { | |
_isFormValid.postValue(true) | |
} else { | |
_isFormValid.postValue(false) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment