// // PasswordInputViewController.swift // GME Remit // // Created by Amrit Giri on 6/25/20. // Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved. // import UIKit class PasswordInputViewController: UIViewController { @IBOutlet weak var passwordTextField: ValidationTextField! @IBOutlet weak var doneBtn: UIButton! @IBOutlet weak var cancelBtn: UIButton! @IBOutlet weak var titleLbl: UILabel! private var validDic = [ "pw": false ] var enteredPassword: ((String)->())? private var isValid = false { didSet { doneBtn.isEnabled = isValid doneBtn.backgroundColor = isValid ? .themeRed : .lightGray } } override func viewDidLoad() { super.viewDidLoad() self.isValid = false self.cancelBtn.isEnabled = true passwordTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged) passwordTextField.validCondition = { $0.count > 5 } passwordTextField.isSecureTextEntry = true titleLbl.text = "enter_login_password_text".localized() passwordTextField.errorMessage = "password_policy_error".localized() passwordTextField.titleText = "password_text".localized() passwordTextField.placeholder = "enter_login_password_text".localized() doneBtn.setTitle("done_text".localized(), for: .normal) passwordTextField.becomeFirstResponder() // Do any additional setup after loading the view. } @objc private func editingChanged(_ textField: ValidationTextField) { switch textField { case passwordTextField: validDic["pw"] = passwordTextField.isValid default: () } isValid = validDic.allSatisfy { $0.value } } @IBAction func done(_ sender: UIButton) { self.enteredPassword?(self.passwordTextField.text ?? "") self.dismiss(animated: true, completion: nil) } @IBAction func cancel(_ sender: UIButton) { self.dismiss(animated: true, completion: nil) } }