I am new to RxSwift and RxCocoa and I'm learning it.
I want to validate all textfield on button click and based on the validation I need to show alert message to user.
After validation is successful I need to insert record in table.
Refer the following code...
var result = txtFname.rx.text
result.asObservable().subscribe(onNext: { text in
if text!.isEmpty {
self.showAlert(msg: "Plese enter first name.")
self.txtFname.becomeFirstResponder()
}
}).disposed(by: disposeBag)
result = txtLname.rx.text
result.asObservable().subscribe(onNext: { text in
if text!.isEmpty {
self.showAlert(msg: "Please enter last name.")
self.txtLname.becomeFirstResponder()
}
}).disposed(by: disposeBag)
result = txtEmail.rx.text
result.asObservable().subscribe(onNext: { text in
if text!.isEmpty {
self.showAlert(msg: "Please enter email id.")
self.txtLname.becomeFirstResponder()
}
}).disposed(by: disposeBag)
//need to check here if all fields are valid or not
//if all fields are valid then insert record....
When I press a button and it check all the validation at one and show alert...
But I want to do like if one validation is fail then it should not go further until previous validation is successful...
I don't know how to achieve this. Any help will be appreciated.