1

I have the following code

submitButtonClickObservable
    .withLatestFrom(txtInputChangesObservable)
    .subscribe{  }

It works well, but i want to handle clicking the submit button while the text input is not used and show the validation error. Is it possible to do it only with Rx without using variables like var text: CharSequence or accessing EditText value?

withLatestFrom marble: http://rxmarbles.com/#withLatestFrom

Nariman Ermekov
  • 185
  • 1
  • 11
  • Can you edit this to explain where `txtInputchangesObservable` comes from? It looks like you can just do your validation right there in the `subscribe` block, no? Perhaps I'm missing context. – AdamMc331 Oct 08 '18 at 03:35

1 Answers1

0

My solution is to add .mergeWith(Observable.just("")) to txtInputChangesObservable. And now subscribe{ } block works on button click even if user didn't use the text input

@Test
fun textObs(){
    val submitButtonClickObservable = Observable.just(Any(), Any())
    val txtInputChangesObservable = Observable.empty<CharSequence>()
            .mergeWith(Observable.just(""))
    val testObserver = submitButtonClickObservable
            .withLatestFrom(txtInputChangesObservable).test()
    testObserver.assertValueCount(2)
}
Nariman Ermekov
  • 185
  • 1
  • 11