0

This is my ViewModel core code

let isEnable = Observable.combineLatest(input.username, input.password) { u, p in
     return u?.isEmpty == false && p?.isEmpty == false
}.asDriver(onErrorJustReturn: false)

Driver code

ouputs.isLoginButtonEnable.debug("v1", trimOutput: false).drive(self.loginButton.rx.valid).disposed(by: bag)

Set text with code

@IBAction func CT(_ sender: Any) {
//        not working
//        self.usernameTF.text = "111"
//        self.passwordTF.text = "222"

//        also not working
//        self.usernameTF.rx.text.onNext("1111")
//        self.passwordTF.rx.text.onNext("3333")
}

I want to bind the UITextField text to determine whether the login button is clickable or not.

It works fine with manual text input.

It does not work when I use the code to set the text property.

Can anyone help me?

Nansen
  • 1
  • 1
  • Here is my code : https://github.com/kfxiaoxia/LoginRx – Nansen Jul 12 '22 at 08:17
  • 1
    This is correct behavior. UIControl observables, just like @IBActions, do not get triggered when the code updates the text. The fact that you _want_ it to update is the problem. Why do you want that? – Daniel T. Jul 12 '22 at 11:09

1 Answers1

0

I agreed with the reply of @Daniel T above, this is the correct behavior. But if you still wanna observe the event please use:

textField.text = "New Text"
textField.sendActions(for: .editingChanged)

With this, you can observe the event with RxSwift when you set the text manual into UITextField.