How to track if textField value is changed by rxSwift?

Viewed 228

Here is my case:

I've got an alert with textfield. When l add a wrong link into this textfield and press send button, I've got an error - Your link is incorrect. I filtered it by keywords - like "facebook" is entered - okay, this link is correct.

But when I start texting new link at this alert after entering a wrong link, the error text don't remove.

How can I track if textField value is changed and remove this error text correctly?

Here is my code:

button.rx
        .tap
        .bind { [weak self] _ in
            guard let self = self else { return }
            let text = self.textField.text ?? ""
            guard
                text.contains(self.viewModel.socialType.urlSubstring) else {
                self.textField.textColor = .red
                self.errorLabel.text = self.viewModel.socialType.error
                return
            }
            self.textField.textColor = .black
            self.viewModel.onSend()
        }
        .disposed(by: bag)
}

Thank you!

1 Answers

For example, you can do this:

textField
    .rx.text.orEmpty
    .debounce(.milliseconds(30), scheduler: MainScheduler.instance)//checking timeout
    .subscribe(onNext: { [weak errorLabel = self.errorLabel] _ in
        errorLabel?.text = nil
    }
    .disposed(by: bag)
Related