more room for validation
This commit is contained in:
parent
ba28929d9e
commit
f8025eb67a
@ -259,6 +259,21 @@ import UIKit
|
||||
resignFirstResponder()
|
||||
}
|
||||
|
||||
@objc public func updateValidation(_ isValid: Bool) {
|
||||
let previousValidity = self.isValid
|
||||
self.isValid = isValid
|
||||
|
||||
if previousValidity && !isValid {
|
||||
shouldShowError(true)
|
||||
} else if (!previousValidity && isValid) {
|
||||
shouldShowError(false)
|
||||
}
|
||||
}
|
||||
|
||||
func shouldShowError(_ showError: Bool) {
|
||||
self.showError = showError
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - MoleculeViewProtocol
|
||||
//--------------------------------------------------
|
||||
@ -285,6 +300,18 @@ import UIKit
|
||||
|
||||
entryFieldContainer.set(with: model, delegateObject, additionalData)
|
||||
|
||||
model.updateUI = { [weak self] in
|
||||
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||
guard let self = self else { return }
|
||||
|
||||
if self.isSelected {
|
||||
self.updateValidation(model.isValid ?? true)
|
||||
} else if model.isValid ?? true && self.showError {
|
||||
self.showError = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
title = model.title
|
||||
feedback = model.feedback
|
||||
isEnabled = model.enabled
|
||||
|
||||
@ -71,12 +71,13 @@ import Foundation
|
||||
}
|
||||
|
||||
public func setValidity(_ valid: Bool, rule: RulesProtocol) {
|
||||
if let fieldKey = fieldKey,
|
||||
let ruleErrorMessage = rule.errorMessage?[fieldKey] {
|
||||
|
||||
if let fieldKey = fieldKey, let ruleErrorMessage = rule.errorMessage?[fieldKey] {
|
||||
self.errorMessage = ruleErrorMessage
|
||||
}
|
||||
|
||||
self.isValid = valid
|
||||
|
||||
updateUI?()
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -236,27 +236,6 @@ import UIKit
|
||||
super.validateText()
|
||||
}
|
||||
|
||||
@objc public func updateValidation(_ isValid: Bool) {
|
||||
let previousValidity = self.isValid
|
||||
self.isValid = isValid
|
||||
|
||||
if previousValidity && !isValid {
|
||||
shouldShowError(true)
|
||||
} else if (!previousValidity && isValid) {
|
||||
shouldShowError(false)
|
||||
}
|
||||
}
|
||||
|
||||
func shouldShowError(_ showError: Bool) {
|
||||
self.showError = showError
|
||||
if showError {
|
||||
observingTextFieldDelegate?.isValid?(textfield: self)
|
||||
entryFieldContainer.originalUI()
|
||||
} else {
|
||||
observingTextFieldDelegate?.isInvalid?(textfield: self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Executes on UITextField.textDidBeginEditingNotification
|
||||
@objc override func startEditing() {
|
||||
super.startEditing()
|
||||
@ -310,6 +289,16 @@ import UIKit
|
||||
}
|
||||
}
|
||||
|
||||
override func shouldShowError(_ showError: Bool) {
|
||||
super.shouldShowError(showError)
|
||||
|
||||
if showError {
|
||||
observingTextFieldDelegate?.isValid?(textfield: self)
|
||||
} else {
|
||||
observingTextFieldDelegate?.isInvalid?(textfield: self)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - MoleculeViewProtocol
|
||||
//--------------------------------------------------
|
||||
@ -319,16 +308,6 @@ import UIKit
|
||||
|
||||
guard let model = model as? TextEntryFieldModel else { return }
|
||||
|
||||
model.updateUI = { [weak self] in
|
||||
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||
guard let self = self else { return }
|
||||
|
||||
if self.isSelected {
|
||||
self.updateValidation(model.isValid ?? true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
self.delegateObject = delegateObject
|
||||
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
||||
text = model.text
|
||||
|
||||
@ -217,6 +217,10 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
||||
showError = !isValid
|
||||
}
|
||||
|
||||
override func shouldShowError(_ showError: Bool) {
|
||||
super.shouldShowError(showError)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - MoleculeViewProtocol
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -42,6 +42,11 @@ public class RuleEqualsIgnoreCaseModel: RulesProtocol {
|
||||
if let fieldValue = formField.formFieldValue() as? String,
|
||||
compareString.caseInsensitiveCompare(fieldValue) == .orderedSame {
|
||||
valid = true
|
||||
for formKey in fields {
|
||||
guard let formField = fieldMolecules[formKey] else { continue }
|
||||
(formField as? FormRuleWatcherFieldProtocol)?.setValidity(true, rule: self)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
(formField as? FormRuleWatcherFieldProtocol)?.setValidity(valid, rule: self)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user