diff --git a/GMERemittance/Module/New Group/kycForm1/Application Logic/Interactor/kycForm1Interactor.swift b/GMERemittance/Module/New Group/kycForm1/Application Logic/Interactor/kycForm1Interactor.swift
index 263ca723..3fd967ad 100644
--- a/GMERemittance/Module/New Group/kycForm1/Application Logic/Interactor/kycForm1Interactor.swift
+++ b/GMERemittance/Module/New Group/kycForm1/Application Logic/Interactor/kycForm1Interactor.swift
@@ -21,11 +21,40 @@ class KycForm1Interactor {
self.service = service
}
+ func _validate(model: kycForm1Model) -> ([String: String]) {
+ var errorDick: [String: String] = [:]
+ let formDick =
+ [
+ KycForm1FieldKeys.firstName: model.firstName,
+ KycForm1FieldKeys.lastName: model.lastName,
+ KycForm1FieldKeys.middleName: model.middleName,
+ KycForm1FieldKeys.gender: model.gender,
+ KycForm1FieldKeys.email: model.email,
+ KycForm1FieldKeys.dob: model.dob,
+ KycForm1FieldKeys.nativeCountry: model.nativeCountry,
+ KycForm1FieldKeys.country: model.country,
+ KycForm1FieldKeys.occupation: model.occupation,
+ KycForm1FieldKeys.province: model.province,
+ KycForm1FieldKeys.mobileNumber: model.mobile
+ ]
+
+
+ formDick.forEach({
+ if $0.value.isEmpty {
+ errorDick[$0.key] = "required"
+ }
+ })
+ return errorDick
+ }
// MARK: Converting entities
}
// MARK: KycForm1 interactor input interface
extension KycForm1Interactor: KycForm1InteractorInput {
-
+ func validate(model: kycForm1Model) {
+ let result = self._validate(model: model)
+ self.output?.show(errors: result)
+
+ }
}
diff --git a/GMERemittance/Module/New Group/kycForm1/Application Logic/Interactor/kycForm1InteractorIO.swift b/GMERemittance/Module/New Group/kycForm1/Application Logic/Interactor/kycForm1InteractorIO.swift
index 46200503..2cbdd821 100644
--- a/GMERemittance/Module/New Group/kycForm1/Application Logic/Interactor/kycForm1InteractorIO.swift
+++ b/GMERemittance/Module/New Group/kycForm1/Application Logic/Interactor/kycForm1InteractorIO.swift
@@ -7,9 +7,9 @@
//
protocol KycForm1InteractorInput: class {
-
+ func validate(model: kycForm1Model)
}
protocol KycForm1InteractorOutput: class {
-
+ func show(errors: [String: String])
}
diff --git a/GMERemittance/Module/New Group/kycForm1/Application Logic/Service/kycForm1ServiceType.swift b/GMERemittance/Module/New Group/kycForm1/Application Logic/Service/kycForm1ServiceType.swift
index afc1d9c0..1d8b0079 100644
--- a/GMERemittance/Module/New Group/kycForm1/Application Logic/Service/kycForm1ServiceType.swift
+++ b/GMERemittance/Module/New Group/kycForm1/Application Logic/Service/kycForm1ServiceType.swift
@@ -11,3 +11,4 @@ import Foundation
protocol KycForm1ServiceType: class {
}
+
diff --git a/GMERemittance/Module/New Group/kycForm1/Module Interface/kycForm1ModuleInterface.swift b/GMERemittance/Module/New Group/kycForm1/Module Interface/kycForm1ModuleInterface.swift
index 8fa4f115..4e2b4c03 100644
--- a/GMERemittance/Module/New Group/kycForm1/Module Interface/kycForm1ModuleInterface.swift
+++ b/GMERemittance/Module/New Group/kycForm1/Module Interface/kycForm1ModuleInterface.swift
@@ -7,5 +7,5 @@
//
protocol KycForm1ModuleInterface: class {
-
+ func validate(model: kycForm1Model)
}
diff --git a/GMERemittance/Module/New Group/kycForm1/User Interface/Presenter/kycForm1Presenter.swift b/GMERemittance/Module/New Group/kycForm1/User Interface/Presenter/kycForm1Presenter.swift
index a5116543..69924400 100644
--- a/GMERemittance/Module/New Group/kycForm1/User Interface/Presenter/kycForm1Presenter.swift
+++ b/GMERemittance/Module/New Group/kycForm1/User Interface/Presenter/kycForm1Presenter.swift
@@ -22,11 +22,15 @@ class KycForm1Presenter {
// MARK: KycForm1 module interface
extension KycForm1Presenter: KycForm1ModuleInterface {
-
+ func validate(model: kycForm1Model) {
+ self.interactor?.validate(model: model)
+ }
}
// MARK: KycForm1 interactor output interface
extension KycForm1Presenter: KycForm1InteractorOutput {
-
+ func show(errors: [String : String]) {
+ self.view?.show(errors: errors)
+ }
}
diff --git a/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1.storyboard b/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1.storyboard
index 33343490..b8b6cd93 100644
--- a/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1.storyboard
+++ b/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1.storyboard
@@ -26,29 +26,29 @@
-
+
-
+
-
+
-
+
-
+
-
+
@@ -95,10 +95,10 @@
-
+
-
+
@@ -127,10 +127,10 @@
-
+
-
+
@@ -159,10 +159,10 @@
-
+
-
+
@@ -191,10 +191,10 @@
-
+
-
+
@@ -223,10 +223,10 @@
-
+
-
+
@@ -255,10 +255,10 @@
-
+
-
+
@@ -287,10 +287,10 @@
-
+
-
+
@@ -319,10 +319,10 @@
-
+
-
+
@@ -351,10 +351,10 @@
-
+
-
+
@@ -383,10 +383,10 @@
-
+
-
+
@@ -420,7 +420,7 @@
-
+
diff --git a/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1ViewController.swift b/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1ViewController.swift
index f687ad28..fad54319 100644
--- a/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1ViewController.swift
+++ b/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1ViewController.swift
@@ -9,25 +9,42 @@
import UIKit
import XLPagerTabStrip
+class kycForm1Model {
+ var firstName = ""
+ var middleName = ""
+ var lastName = ""
+ var gender = ""
+ var dob = ""
+ var mobile = ""
+ var email = ""
+ var nativeCountry = ""
+ var country = ""
+ var province = ""
+ var occupation = ""
+}
+
+struct KycForm1FieldKeys {
+ static let firstName = "firstName"
+ static let middleName = "middleName"
+ static let lastName = "lastName"
+ static let gender = "gender"
+ static let dob = "dob"
+ static let mobileNumber = "mobileNumber"
+ static let email = "email"
+ static let nativeCountry = "nativeCountry"
+ static let country = "country"
+ static let province = "province"
+ static let occupation = "occupation"
+}
+
class KycForm1ViewController: UIViewController {
struct Constants {
static let segmentBackgroundViewColor = UIColor.init(hex: "E7EDF2")
+ static let stateRedColor = UIColor.init(hex: "#EC1C24")
}
- struct FieldKeys {
- static let firstName = "firstName"
- static let middleName = "middleName"
- static let lastName = "lastName"
- static let gender = "gender"
- static let dob = "dob"
- static let mobileNumber = "mobileNumber"
- static let email = "email"
- static let nativeCountry = "nativeCountry"
- static let country = "country"
- static let province = "province"
- static let occupation = "occupation"
- }
+
// MARK: IBOutlets
// validation labels
@@ -57,14 +74,16 @@ class KycForm1ViewController: UIViewController {
@IBOutlet weak var occupationTextField: UITextField!
-
-
// MARK: Properties
var presenter: KycForm1ModuleInterface?
+ var kycModel: kycForm1Model = kycForm1Model()
var errorTextFieldDict: [String: UITextField] = [:]
var errorLabelsDict: [String: UILabel] = [:]
+
+ var errorLabels: [UILabel] = []
+ var textfields: [UITextField] = []
// MARK: VC's Life cycle
@@ -76,7 +95,18 @@ class KycForm1ViewController: UIViewController {
// MARK: IBActions
@IBAction func save(_ sender: UIButton) {
-
+ self.kycModel.firstName = self.firstNameTextField.text!
+ self.kycModel.middleName = self.middleNmaeTextField.text!
+ self.kycModel.lastName = self.lastNameTextField.text!
+ self.kycModel.gender = self.genderTextField.text!
+ self.kycModel.dob = self.dobTextField.text!
+ self.kycModel.mobile = self.mobileNumberTextField.text!
+ self.kycModel.email = self.emailTextField.text!
+ self.kycModel.nativeCountry = self.nativeCountryTextField.text!
+ self.kycModel.country = self.countryTextField.text!
+ self.kycModel.province = self.provinceTextField.text!
+ self.kycModel.occupation = self.occupationTextField.text!
+ validate()
}
// MARK: Other Functions
@@ -86,6 +116,25 @@ class KycForm1ViewController: UIViewController {
hideErrorLabels()
setupErrorLabels()
setupErrorTextFields()
+ setupDelegates()
+ }
+
+ private func setupDelegates() {
+ self.firstNameTextField.delegate = self
+ self.lastNameTextField.delegate = self
+ self.middleNmaeTextField.delegate = self
+ self.genderTextField.delegate = self
+ self.emailTextField.delegate = self
+ self.dobTextField.delegate = self
+ self.countryTextField.delegate = self
+ self.nativeCountryTextField.delegate = self
+ self.occupationTextField.delegate = self
+ self.mobileNumberTextField.delegate = self
+ self.provinceTextField.delegate = self
+ }
+
+ private func validate() {
+ self.presenter?.validate(model: self.kycModel)
}
private func hideErrorLabels() {
@@ -95,43 +144,70 @@ class KycForm1ViewController: UIViewController {
}
private func setupErrorLabels() {
+ self.errorLabels = [firstNameErrorLabel, middleNameErrorLabel, lastNameErrorLabel, genderErrorLabel, dobErrorLabel, mobileNumberErrorLabel, emailErrorLabel, nativeCountryErrorLabel, nativeCountryErrorLabel, provinceErrorLabel, occupationErrorLabel]
+
self.errorLabelsDict =
[
- FieldKeys.firstName: self.firstNameErrorLabel,
- FieldKeys.middleName: self.middleNameErrorLabel,
- FieldKeys.lastName: self.lastNameErrorLabel,
- FieldKeys.gender: self.genderErrorLabel,
- FieldKeys.dob: self.dobErrorLabel,
- FieldKeys.mobileNumber: self.mobileNumberErrorLabel,
- FieldKeys.email: self.emailErrorLabel,
- FieldKeys.nativeCountry: self.nativeCountryErrorLabel,
- FieldKeys.country: self.countryErrorLabel,
- FieldKeys.province: self.provinceErrorLabel,
- FieldKeys.occupation: self.occupationErrorLabel
+ KycForm1FieldKeys.firstName: self.firstNameErrorLabel,
+ KycForm1FieldKeys.middleName: self.middleNameErrorLabel,
+ KycForm1FieldKeys.lastName: self.lastNameErrorLabel,
+ KycForm1FieldKeys.gender: self.genderErrorLabel,
+ KycForm1FieldKeys.dob: self.dobErrorLabel,
+ KycForm1FieldKeys.mobileNumber: self.mobileNumberErrorLabel,
+ KycForm1FieldKeys.email: self.emailErrorLabel,
+ KycForm1FieldKeys.nativeCountry: self.nativeCountryErrorLabel,
+ KycForm1FieldKeys.country: self.countryErrorLabel,
+ KycForm1FieldKeys.province: self.provinceErrorLabel,
+ KycForm1FieldKeys.occupation: self.occupationErrorLabel
]
}
private func setupErrorTextFields() {
+
+ self.textfields = [firstNameTextField, lastNameTextField, middleNmaeTextField, genderTextField, dobTextField, mobileNumberTextField, emailTextField, nativeCountryTextField, countryTextField, provinceTextField, occupationTextField]
+
self.errorTextFieldDict =
[
- FieldKeys.firstName: self.firstNameTextField,
- FieldKeys.middleName: self.middleNmaeTextField,
- FieldKeys.lastName: self.lastNameTextField,
- FieldKeys.gender: self.genderTextField,
- FieldKeys.dob: self.dobTextField,
- FieldKeys.mobileNumber: self.mobileNumberTextField,
- FieldKeys.email: self.emailTextField,
- FieldKeys.nativeCountry: self.nativeCountryTextField,
- FieldKeys.country: self.countryTextField,
- FieldKeys.province: self.provinceTextField,
- FieldKeys.occupation: self.occupationTextField
+ KycForm1FieldKeys.firstName: self.firstNameTextField,
+ KycForm1FieldKeys.middleName: self.middleNmaeTextField,
+ KycForm1FieldKeys.lastName: self.lastNameTextField,
+ KycForm1FieldKeys.gender: self.genderTextField,
+ KycForm1FieldKeys.dob: self.dobTextField,
+ KycForm1FieldKeys.mobileNumber: self.mobileNumberTextField,
+ KycForm1FieldKeys.email: self.emailTextField,
+ KycForm1FieldKeys.nativeCountry: self.nativeCountryTextField,
+ KycForm1FieldKeys.country: self.countryTextField,
+ KycForm1FieldKeys.province: self.provinceTextField,
+ KycForm1FieldKeys.occupation: self.occupationTextField
]
}
+
+ private func showBorder(textfield :UITextField?) {
+ guard let textfield = textfield else {return}
+ textfield.layer.borderColor = Constants.stateRedColor.cgColor
+ textfield.layer.borderWidth = 1
+ }
+
+ private func show( error: String, label: UILabel?) {
+ guard let label = label else {return}
+ label.textColor = Constants.stateRedColor
+ label.isHidden = false
+ label.text = error
+ }
}
// MARK: KycForm1ViewInterface
extension KycForm1ViewController: KycForm1ViewInterface {
-
+ func show(errors: [String : String]) {
+ print(errors)
+ errors.forEach({
+ let label = errorLabelsDict[$0.key]
+ self.show(error: $0.value, label: label)
+ let textfield = errorTextFieldDict[$0.key]
+ self.showBorder(textfield: textfield)
+
+ })
+ }
}
extension KycForm1ViewController: IndicatorInfoProvider {
@@ -139,3 +215,45 @@ extension KycForm1ViewController: IndicatorInfoProvider {
return IndicatorInfo.init(title: "Personal")
}
}
+
+extension KycForm1ViewController: UITextFieldDelegate {
+ func textFieldDidBeginEditing(_ textField: UITextField) {
+ switch textField {
+ case firstNameTextField:
+ self.firstNameErrorLabel.isHidden = true
+ firstNameTextField.layer.borderWidth = 0
+ case middleNmaeTextField:
+ self.middleNameErrorLabel.isHidden = true
+ middleNmaeTextField.layer.borderWidth = 0
+ case lastNameTextField:
+ self.lastNameErrorLabel.isHidden = true
+ lastNameTextField.layer.borderWidth = 0
+ case genderTextField:
+ self.genderErrorLabel.isHidden = true
+ genderTextField.layer.borderWidth = 0
+ case dobTextField:
+ self.dobErrorLabel.isHidden = true
+ dobTextField.layer.borderWidth = 0
+ case mobileNumberTextField:
+ self.mobileNumberErrorLabel.isHidden = true
+ mobileNumberTextField.layer.borderWidth = 0
+ case emailTextField:
+ self.emailErrorLabel.isHidden = true
+ emailTextField.layer.borderWidth = 0
+ case nativeCountryTextField:
+ self.nativeCountryErrorLabel.isHidden = true
+ nativeCountryTextField.layer.borderWidth = 0
+ case countryTextField:
+ self.countryErrorLabel.isHidden = true
+ countryTextField.layer.borderWidth = 0
+ case provinceTextField:
+ self.provinceErrorLabel.isHidden = true
+ provinceTextField.layer.borderWidth = 0
+ case occupationTextField:
+ self.occupationErrorLabel.isHidden = true
+ occupationTextField.layer.borderWidth = 0
+ default:
+ break
+ }
+ }
+}
diff --git a/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1ViewInterface.swift b/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1ViewInterface.swift
index c9dd437c..74c606d1 100644
--- a/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1ViewInterface.swift
+++ b/GMERemittance/Module/New Group/kycForm1/User Interface/View/kycForm1ViewInterface.swift
@@ -7,4 +7,5 @@
//
protocol KycForm1ViewInterface: class {
+ func show(errors: [String :String])
}