From dc8293b08b6bce9b2aa617c5fe63609410a139d3 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 22 Nov 2019 14:33:46 -0500 Subject: [PATCH] more refinement of errors. --- MVMCoreUI/Atoms/TextFields/DigitBox.swift | 1 + .../Atoms/TextFields/DigitEntryField.swift | 3 +-- MVMCoreUI/Atoms/TextFields/EntryField.swift | 2 +- .../Atoms/TextFields/TextEntryField.swift | 18 ++++++++---------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atoms/TextFields/DigitBox.swift b/MVMCoreUI/Atoms/TextFields/DigitBox.swift index d104412a..8cdbcd4f 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitBox.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitBox.swift @@ -124,6 +124,7 @@ import UIKit } @objc public func textFieldDidDelete() { + digitBoxDelegate?.digitFieldDidDelete?(digitField) } diff --git a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift index 97728ce0..1532e0a3 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift @@ -65,8 +65,7 @@ import UIKit for (index, field) in digitBoxes.enumerated() { if index < newValue.count { let indexChar = newValue.index(newValue.startIndex, offsetBy: index) - field.digitField.attributedPlaceholder = NSAttributedString(string: String(newValue[indexChar]), attributes: [ - NSAttributedString.Key.foregroundColor: UIColor.mfBattleshipGrey()]) + field.digitField.attributedPlaceholder = NSAttributedString(string: String(newValue[indexChar]), attributes: [NSAttributedString.Key.foregroundColor: UIColor.mfBattleshipGrey()]) } } diff --git a/MVMCoreUI/Atoms/TextFields/EntryField.swift b/MVMCoreUI/Atoms/TextFields/EntryField.swift index 5771b300..2bea185e 100644 --- a/MVMCoreUI/Atoms/TextFields/EntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/EntryField.swift @@ -52,7 +52,7 @@ import UIKit public var errorMessage: String? /// Determines whther the feedback label will clear itself after user interaction or display update. -// public var fixedFeedback: Bool = false + public var affixFeedback: Bool = false //-------------------------------------------------- // MARK: - Computed Properties diff --git a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift index 44cf9572..01636109 100644 --- a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift @@ -90,7 +90,9 @@ import UIKit //-------------------------------------------------- public var validationBlock: ((_ value: String?) -> Bool)? { - didSet { valueChanged() } + didSet { //valueChanged() + + } } public override var errorMessage: String? { @@ -214,21 +216,19 @@ import UIKit /// Executes on UITextField.textDidChangeNotification @objc func valueChanged() { - if !showError { + if !showError && !affixFeedback { feedback = "" } - - let previousValidity = isValid - + // If validation not set, input will always be valid isValid = validationBlock?(text) ?? true - if previousValidity && !isValid { + if !isValid { showError = true observingTextFieldDelegate?.isInvalid?(textfield: self) - } else if !previousValidity && isValid { - showError = false + } else if isValid { + isSelected = true observingTextFieldDelegate?.isValid?(textfield: self) } } @@ -240,8 +240,6 @@ import UIKit showError = false entryFieldContainer.bottomBar?.backgroundColor = UIColor.black.cgColor - } else if let errMessage = errorMessage { - feedback = errMessage } }