refactored out more code into enums
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
5672df7070
commit
f93239b421
@ -9,10 +9,11 @@ import Foundation
|
||||
import UIKit
|
||||
|
||||
extension InputField {
|
||||
|
||||
public enum FieldType: String, CaseIterable {
|
||||
case text, number, inlineAction, password, creditCard, tel, date, securityCode
|
||||
|
||||
public var keyboardType: UIKeyboardType {
|
||||
internal var keyboardType: UIKeyboardType {
|
||||
switch self {
|
||||
case .number:
|
||||
.numberPad
|
||||
@ -28,5 +29,41 @@ extension InputField {
|
||||
.default
|
||||
}
|
||||
}
|
||||
|
||||
internal func appendRules(for textField: InputField) {
|
||||
switch self {
|
||||
case .creditCard:
|
||||
if let text = textField.text, text.count > 0 {
|
||||
let rule = CharacterCountRule().copyWith {
|
||||
$0.maxLength = textField.creditCardType.maxLength
|
||||
$0.compareType = .equals
|
||||
$0.errorMessage = "Enter a valid credit card."
|
||||
}
|
||||
textField.rules.append(.init(rule))
|
||||
}
|
||||
|
||||
case .tel:
|
||||
if let text = textField.text, text.count > 0 {
|
||||
let rule = CharacterCountRule().copyWith {
|
||||
$0.maxLength = "XXX-XXX-XXXX".count
|
||||
$0.compareType = .equals
|
||||
$0.errorMessage = "Enter a valid telephone."
|
||||
}
|
||||
textField.rules.append(.init(rule))
|
||||
}
|
||||
case .date:
|
||||
if let text = textField.text, text.count > 0 {
|
||||
let rule = CharacterCountRule().copyWith {
|
||||
$0.maxLength = textField.dateFormat.maxLength
|
||||
$0.compareType = .equals
|
||||
$0.errorMessage = "Enter a valid date."
|
||||
}
|
||||
textField.rules.append(.init(rule))
|
||||
}
|
||||
default: break
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,7 +312,7 @@ open class InputField: EntryFieldBase {
|
||||
|
||||
//leftIcon
|
||||
if let leftImageName {
|
||||
leftImageView.image = BundleManager.shared.image(for: creditCardType.imageName)?.withTintColor(iconColorConfiguration.getColor(self))
|
||||
leftImageView.image = BundleManager.shared.image(for: leftImageName)?.withTintColor(iconColorConfiguration.getColor(self))
|
||||
}
|
||||
leftImageView.isHidden = leftImageName == nil
|
||||
|
||||
@ -349,39 +349,7 @@ open class InputField: EntryFieldBase {
|
||||
|
||||
override func updateRules() {
|
||||
super.updateRules()
|
||||
|
||||
switch fieldType {
|
||||
case .creditCard:
|
||||
if let text = textField.text, text.count > 0 {
|
||||
let rule = CharacterCountRule().copyWith {
|
||||
$0.maxLength = creditCardType.maxLength
|
||||
$0.compareType = .equals
|
||||
$0.errorMessage = "Enter a valid credit card."
|
||||
}
|
||||
rules.append(.init(rule))
|
||||
}
|
||||
|
||||
case .tel:
|
||||
if let text = textField.text, text.count > 0 {
|
||||
let rule = CharacterCountRule().copyWith {
|
||||
$0.maxLength = "XXX-XXX-XXXX".count
|
||||
$0.compareType = .equals
|
||||
$0.errorMessage = "Enter a valid telephone."
|
||||
}
|
||||
rules.append(.init(rule))
|
||||
}
|
||||
case .date:
|
||||
if let text = textField.text, text.count > 0 {
|
||||
let rule = CharacterCountRule().copyWith {
|
||||
$0.maxLength = dateFormat.maxLength
|
||||
$0.compareType = .equals
|
||||
$0.errorMessage = "Enter a valid date."
|
||||
}
|
||||
rules.append(.init(rule))
|
||||
}
|
||||
default: break
|
||||
|
||||
}
|
||||
fieldType.appendRules(for: self)
|
||||
}
|
||||
|
||||
/// Used to update any Accessibility properties.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user