Merge branch 'develop' into feature/new_take_textview
This commit is contained in:
commit
7178ade848
@ -71,7 +71,12 @@ import Foundation
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func setValidity(_ valid: Bool, rule: RulesProtocol) {
|
public func setValidity(_ valid: Bool, rule: RulesProtocol) {
|
||||||
|
if let fieldKey = fieldKey,
|
||||||
|
let ruleErrorMessage = rule.errorMessage?[fieldKey] {
|
||||||
|
self.errorMessage = ruleErrorMessage
|
||||||
|
}
|
||||||
self.isValid = valid
|
self.isValid = valid
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -244,14 +244,21 @@ import UIKit
|
|||||||
self.isValid = isValid
|
self.isValid = isValid
|
||||||
|
|
||||||
if previousValidity && !isValid {
|
if previousValidity && !isValid {
|
||||||
showError = true
|
shouldShowError(true)
|
||||||
observingTextFieldDelegate?.isInvalid?(textfield: self)
|
|
||||||
} else if (!previousValidity && isValid) {
|
} else if (!previousValidity && isValid) {
|
||||||
showError = false
|
shouldShowError(false)
|
||||||
observingTextFieldDelegate?.isValid?(textfield: self)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func shouldShowError(_ showError: Bool) {
|
||||||
|
self.showError = showError
|
||||||
|
if showError {
|
||||||
|
observingTextFieldDelegate?.isValid?(textfield: self)
|
||||||
|
entryFieldContainer.originalUI()
|
||||||
|
} else {
|
||||||
|
observingTextFieldDelegate?.isInvalid?(textfield: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes on UITextField.textDidBeginEditingNotification
|
/// Executes on UITextField.textDidBeginEditingNotification
|
||||||
@objc func startEditing() {
|
@objc func startEditing() {
|
||||||
isSelected = true
|
isSelected = true
|
||||||
@ -268,10 +275,16 @@ import UIKit
|
|||||||
/// Executes on UITextField.textDidEndEditingNotification
|
/// Executes on UITextField.textDidEndEditingNotification
|
||||||
@objc func endInputing() {
|
@objc func endInputing() {
|
||||||
resignFirstResponder()
|
resignFirstResponder()
|
||||||
if isValid {
|
|
||||||
showError = false
|
// Don't show error till user starts typing.
|
||||||
entryFieldContainer.bottomBar?.backgroundColor = UIColor.mvmBlack.cgColor
|
guard text?.count ?? 0 != 0 else {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let isValid = (model as? TextEntryFieldModel)?.isValid {
|
||||||
|
self.isValid = isValid
|
||||||
|
}
|
||||||
|
shouldShowError(!isValid)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func dismissFieldInput(_ sender: Any?) {
|
@objc public func dismissFieldInput(_ sender: Any?) {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public class RuleAllValueChangedModel: RulesProtocol {
|
|||||||
|
|
||||||
public static var identifier: String = "allValueChanged"
|
public static var identifier: String = "allValueChanged"
|
||||||
public var type: String = RuleAllValueChangedModel.identifier
|
public var type: String = RuleAllValueChangedModel.identifier
|
||||||
|
public var errorMessage: [String: String]?
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -17,6 +17,7 @@ public class RuleAnyRequiredModel: RulesProtocol {
|
|||||||
public static var identifier: String = "anyRequired"
|
public static var identifier: String = "anyRequired"
|
||||||
public var type: String = RuleRequiredModel.identifier
|
public var type: String = RuleRequiredModel.identifier
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
|
public var errorMessage: [String: String]?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
|
|||||||
@ -16,6 +16,7 @@ public class RuleAnyValueChangedModel: RulesProtocol {
|
|||||||
|
|
||||||
public static var identifier: String = "anyValueChanged"
|
public static var identifier: String = "anyValueChanged"
|
||||||
public var type: String = RuleAnyValueChangedModel.identifier
|
public var type: String = RuleAnyValueChangedModel.identifier
|
||||||
|
public var errorMessage: [String: String]?
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -17,6 +17,7 @@ public class RuleEqualsModel: RulesProtocol {
|
|||||||
public static var identifier: String = "equals"
|
public static var identifier: String = "equals"
|
||||||
public var type: String = RuleEqualsModel.identifier
|
public var type: String = RuleEqualsModel.identifier
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
|
public var errorMessage: [String: String]?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Validation
|
// MARK: - Validation
|
||||||
@ -27,9 +28,9 @@ public class RuleEqualsModel: RulesProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
|
public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
|
||||||
var valid = true
|
var valid = true
|
||||||
var compareValue: AnyHashable?
|
var compareValue: AnyHashable?
|
||||||
|
|
||||||
for formKey in fields {
|
for formKey in fields {
|
||||||
guard let formField = fieldMolecules[formKey] else { continue }
|
guard let formField = fieldMolecules[formKey] else { continue }
|
||||||
|
|
||||||
@ -37,13 +38,16 @@ public class RuleEqualsModel: RulesProtocol {
|
|||||||
compareValue = formField.formFieldValue()
|
compareValue = formField.formFieldValue()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if compareValue != formField.formFieldValue() {
|
if compareValue != formField.formFieldValue() {
|
||||||
valid = false
|
valid = false
|
||||||
|
(formField as? FormRuleWatcherFieldProtocol)?.setValidity(valid, rule: self)
|
||||||
break
|
break
|
||||||
|
} else {
|
||||||
|
(formField as? FormRuleWatcherFieldProtocol)?.setValidity(valid, rule: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ public class RuleRegexModel: RulesProtocol {
|
|||||||
public var type: String = RuleRegexModel.identifier
|
public var type: String = RuleRegexModel.identifier
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
public var regex: String
|
public var regex: String
|
||||||
|
public var errorMessage: [String: String]?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|||||||
@ -16,6 +16,7 @@ public class RuleRequiredModel: RulesProtocol {
|
|||||||
|
|
||||||
public static var identifier: String = "allRequired"
|
public static var identifier: String = "allRequired"
|
||||||
public var type: String = RuleRequiredModel.identifier
|
public var type: String = RuleRequiredModel.identifier
|
||||||
|
public var errorMessage: [String: String]?
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -16,7 +16,9 @@ public enum RulesCodingKey: String, CodingKey {
|
|||||||
public protocol RulesProtocol: ModelProtocol {
|
public protocol RulesProtocol: ModelProtocol {
|
||||||
// The type of rule
|
// The type of rule
|
||||||
var type: String { get }
|
var type: String { get }
|
||||||
|
|
||||||
|
var errorMessage: [String: String]? { get }
|
||||||
|
|
||||||
// The fields that this rule applies to.
|
// The fields that this rule applies to.
|
||||||
var fields: [String] { get set }
|
var fields: [String] { get set }
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user