This is how I define actions for my password UITextFields
:
mainView.passwordTextField.rx.text.orEmpty.bind(to: viewModel.password).disposed(by: disposeBag)
mainView.passwordTextField.rx.controlEvent([.editingChanged])
.asObservable()
.subscribe { [mainView, viewModel, weak self] ale in
print(">>>>>")
print(viewModel.password.value)
self?.updateView()
}.disposed(by: disposeBag)
And this is how it look like after password autofill is called there:
>>>>>>
cckSG%in51ZZ65y
And when I select from suggest autopassword My own password
all fields are reset and are empty, but nothing is called. And in viewModel.password.value
there is still previous non empty value. How can I resolve it?
2
Answers
editingChanged
is described as "touch event" in UIKit doc. So the system-provided autofill may be simulating touches. The field clearing effect of "My own password" then probably does not simulate touches. Try observe some other control events not related to touches, ultimatelyallEvents
.Thought #2: or subscribe to the
text
itself, not to the control events.I’m not sure entirely what the problem is based on the description but please be aware that
.rx.text
and.rx.controlEvent()
only report changes made by the user, not changes made programmatically. Maybe that is the confusion you are having?Also, the code you post doesn’t make too much sense. You are already binding the changes in
passwordTextField
to the view model’spassword
property (I assume it’s a BehaviorRelay). So why read from it in the subscribe when you are already writing to it in a different subscribe? You can’t really be sure which subscribe’s closure will be called first.