You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

4 years ago
4 years ago
  1. //
  2. // PasswordInputViewController.swift
  3. // GME Remit
  4. //
  5. // Created by Amrit Giri on 6/25/20.
  6. // Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class PasswordInputViewController: UIViewController {
  10. @IBOutlet weak var passwordTextField: ValidationTextField!
  11. @IBOutlet weak var doneBtn: UIButton!
  12. @IBOutlet weak var cancelBtn: UIButton!
  13. @IBOutlet weak var titleLbl: UILabel!
  14. private var validDic = [
  15. "pw": false
  16. ]
  17. var enteredPassword: ((String)->())?
  18. private var isValid = false {
  19. didSet {
  20. // doneBtn.isEnabled = isValid
  21. // doneBtn.backgroundColor = isValid ? .themeRed : .themeText
  22. doneBtn.isEnabled = true
  23. doneBtn.backgroundColor = isValid ? .themeRed : .themeRed
  24. }
  25. }
  26. override func viewDidLoad() {
  27. super.viewDidLoad()
  28. self.isValid = false
  29. self.cancelBtn.isEnabled = true
  30. passwordTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
  31. passwordTextField.validCondition = { !$0.isEmpty && $0.validateRegex(regex: passwordRegex)}
  32. passwordTextField.isSecureTextEntry = true
  33. titleLbl.text = "enter_login_password_text".localized()
  34. passwordTextField.errorMessage = "password_error_text".localized()
  35. passwordTextField.titleText = "password_text".localized()
  36. passwordTextField.placeholder = "enter_login_password_text".localized()
  37. doneBtn.setTitle("done_text".localized(), for: .normal)
  38. passwordTextField.becomeFirstResponder()
  39. // Do any additional setup after loading the view.
  40. }
  41. @objc private func editingChanged(_ textField: ValidationTextField) {
  42. switch textField {
  43. case passwordTextField:
  44. validDic["pw"] = passwordTextField.isValid
  45. default: ()
  46. }
  47. isValid = validDic.allSatisfy { $0.value }
  48. }
  49. @IBAction func done(_ sender: UIButton) {
  50. self.enteredPassword?(self.passwordTextField.text ?? "")
  51. self.dismiss(animated: true, completion: nil)
  52. }
  53. @IBAction func cancel(_ sender: UIButton) {
  54. self.dismiss(animated: true, completion: nil)
  55. }
  56. }