REFERENCE SCREENSHOT:
h ttps://drive.google.com/file/d/1rQ9qZPNoFGCfEndGOEbYLfsIET7TYuEf/view?usp=sharing
Hi,
I am working on a simple form with 5 text fields and a UIButton, particualry the the titleLabel.text property of the that button. What I am trying to do is to peform a check when the user hits the SignUp Button (see link for screenshot). So when the signup button is tapped, I want to run a check to see if:
A. Any of the text fields are empty (thinking about using the isEmpty property)
B. If the Button Label text is still "Tap to choose a role..." If the user selected a role by tapping the button, this text would be replaced by the role which confirms that the user selected a role.
When the check is peformed, if any combination of empty textfields and/or button labels are "invalid" (i.e empty or incorrect label), then I want to display a UIAlertController and the message parameter of the alert would show the textfields and/or button combos that need to be filled.
Any guidance on how to begin would be great, there are so many combinations, that could be possible ( 1 text fields, 2 textfields + button, just the button, etc). Here is my current code, but I dont wanna go down this route since that would be a lot of code writing and its probably not the best solution but a start...
// IBAction function for when the user taps sign up button
@IBAction func whenSignUpButtonIsTapped(_ sender: UIButton) {
//Workflow
// 1. Validation check
// 2. Register User
// 1 validation check...
if (firstNameTextField.text?.isEmpty)! {
let missingInformationAlert = UIAlertController(title: "Missing Information",
message: "First Name is required",
preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
missingInformationAlert.addAction(cancelAction)
self.present(missingInformationAlert, animated: true, completion: nil)
}
Thanks!