I have an alertController, with one textField.. and alertAction button [Save].
When the textField presented (empty), the [Save].isEnabled = false. If user type anything in textField (none space), button [Save].isEnabled = true.
code:
field.addTarget(self, action: #selector(self.alertTextFieldDidChange(_:)), for: .editingChanged)
validation code:
var alertController : UIAlertController?
@objc func alertTextFieldDidChange(_ sender: UITextField) {
alertController?.actions[0].isEnabled = sender.text!.trimmingCharacters(in: .whitespacesAndNewlines).count > 0
}
[Save] button works as expected. However, when I insert text in textField (as default entry):
textField.text = "Test"
textField showing "Text", if user choose to accept the default value "Test", [Save] button isEnabled will not change. User will have to type something in textField.
I need some direction .. Thanks.
-
—
jimmychang26
Add a CommentAnyone? or, maybe I post the question at wrong place?