Merge branch 'feature/no_validate_empty' into 'develop'
No validate empty See merge request BPHV_MIPS/mvm_core_ui!440
This commit is contained in:
commit
23a17ce013
@ -322,7 +322,7 @@ import UIKit
|
|||||||
@objc override open func resignFirstResponder() -> Bool {
|
@objc override open func resignFirstResponder() -> Bool {
|
||||||
|
|
||||||
if validateWhenDoneEditing {
|
if validateWhenDoneEditing {
|
||||||
validateTextField()
|
validateText()
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedDigitBox?.isSelected = false
|
selectedDigitBox?.isSelected = false
|
||||||
@ -440,7 +440,7 @@ extension DigitEntryField {
|
|||||||
selectedDigitBox = nil
|
selectedDigitBox = nil
|
||||||
|
|
||||||
if !switchFieldsAutomatically && validateWhenDoneEditing {
|
if !switchFieldsAutomatically && validateWhenDoneEditing {
|
||||||
validateTextField()
|
validateText()
|
||||||
}
|
}
|
||||||
|
|
||||||
proprietorTextDelegate?.textFieldDidEndEditing?(textField)
|
proprietorTextDelegate?.textFieldDidEndEditing?(textField)
|
||||||
|
|||||||
@ -49,6 +49,9 @@ import UIKit
|
|||||||
|
|
||||||
public var isValid: Bool = false
|
public var isValid: Bool = false
|
||||||
|
|
||||||
|
/// Validate on each entry in the textField. Default: true
|
||||||
|
public var validateEachCharacter: Bool = true
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Computed Properties
|
// MARK: - Computed Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -229,6 +232,48 @@ import UIKit
|
|||||||
entryFieldContainer.updateView(size)
|
entryFieldContainer.updateView(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Validation
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
/// Validates the text of the entry field.
|
||||||
|
@objc public func validateText() {
|
||||||
|
if let isValid = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) {
|
||||||
|
self.isValid = isValid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Executes on .textDidBeginEditingNotification
|
||||||
|
@objc func startEditing() {
|
||||||
|
isSelected = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Executes on .textDidChangeNotification (each character entry)
|
||||||
|
@objc func valueChanged() {
|
||||||
|
guard validateEachCharacter else { return }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Executes on .textDidEndEditingNotification
|
||||||
|
@objc func endInputing() {
|
||||||
|
isSelected = false
|
||||||
|
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
|
// MARK: - MoleculeViewProtocol
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -255,6 +300,18 @@ import UIKit
|
|||||||
|
|
||||||
entryFieldContainer.set(with: model, delegateObject, additionalData)
|
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
|
title = model.title
|
||||||
feedback = model.feedback
|
feedback = model.feedback
|
||||||
isEnabled = model.enabled
|
isEnabled = model.enabled
|
||||||
|
|||||||
@ -71,12 +71,13 @@ 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] {
|
if let fieldKey = fieldKey, let ruleErrorMessage = rule.errorMessage?[fieldKey] {
|
||||||
self.errorMessage = ruleErrorMessage
|
self.errorMessage = ruleErrorMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
self.isValid = valid
|
self.isValid = valid
|
||||||
|
updateUI?()
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -51,9 +51,6 @@ import UIKit
|
|||||||
|
|
||||||
private var observingForChange: Bool = false
|
private var observingForChange: Bool = false
|
||||||
|
|
||||||
/// Validate on each entry in the textField. Default: true
|
|
||||||
public var validateEachCharacter: Bool = true
|
|
||||||
|
|
||||||
/// Validate when user resigns editing. Default: true
|
/// Validate when user resigns editing. Default: true
|
||||||
public var validateWhenDoneEditing: Bool = true
|
public var validateWhenDoneEditing: Bool = true
|
||||||
|
|
||||||
@ -226,7 +223,7 @@ import UIKit
|
|||||||
@discardableResult
|
@discardableResult
|
||||||
@objc override open func resignFirstResponder() -> Bool {
|
@objc override open func resignFirstResponder() -> Bool {
|
||||||
if validateWhenDoneEditing {
|
if validateWhenDoneEditing {
|
||||||
validateTextField()
|
validateText()
|
||||||
}
|
}
|
||||||
textField.resignFirstResponder()
|
textField.resignFirstResponder()
|
||||||
isSelected = false
|
isSelected = false
|
||||||
@ -234,56 +231,37 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Validates the text of the entry field.
|
/// Validates the text of the entry field.
|
||||||
@objc public func validateTextField() {
|
@objc public override func validateText() {
|
||||||
text = textField.text
|
text = textField.text
|
||||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
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
|
/// Executes on UITextField.textDidBeginEditingNotification
|
||||||
@objc func startEditing() {
|
@objc override func startEditing() {
|
||||||
isSelected = true
|
super.startEditing()
|
||||||
textField.becomeFirstResponder()
|
textField.becomeFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes on UITextField.textDidChangeNotification (each character entry)
|
/// Executes on UITextField.textDidChangeNotification (each character entry)
|
||||||
@objc func valueChanged() {
|
@objc override func valueChanged() {
|
||||||
guard validateEachCharacter else { return }
|
super.valueChanged()
|
||||||
isSelected = true
|
validateText()
|
||||||
validateTextField()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes on UITextField.textDidEndEditingNotification
|
/// Executes on UITextField.textDidEndEditingNotification
|
||||||
@objc func endInputing() {
|
@objc override func endInputing() {
|
||||||
resignFirstResponder()
|
super.endInputing()
|
||||||
|
|
||||||
// Don't show error till user starts typing.
|
// Don't show error till user starts typing.
|
||||||
guard text?.count ?? 0 != 0 else {
|
guard text?.count ?? 0 != 0 else {
|
||||||
|
showError = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let isValid = (model as? TextEntryFieldModel)?.isValid {
|
if let isValid = textEntryFieldModel?.isValid {
|
||||||
self.isValid = isValid
|
self.isValid = isValid
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldShowError(!isValid)
|
shouldShowError(!isValid)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,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
|
// MARK: - MoleculeViewProtocol
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -320,16 +308,6 @@ import UIKit
|
|||||||
|
|
||||||
guard let model = model as? TextEntryFieldModel else { return }
|
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
|
self.delegateObject = delegateObject
|
||||||
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
FormValidator.setupValidation(for: model, delegate: delegateObject?.formHolderDelegate)
|
||||||
text = model.text
|
text = model.text
|
||||||
|
|||||||
@ -24,9 +24,6 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Validate on each entry in the textView. Default: true
|
|
||||||
public var validateEachCharacter: Bool = true
|
|
||||||
|
|
||||||
private var observingForChange: Bool = false
|
private var observingForChange: Bool = false
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -71,7 +68,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
|
|
||||||
/// The text of this textView.
|
/// The text of this textView.
|
||||||
open override var text: String? {
|
open override var text: String? {
|
||||||
get { return textView.text }
|
get { return textViewEntryFieldModel?.text }
|
||||||
set {
|
set {
|
||||||
textView.text = newValue
|
textView.text = newValue
|
||||||
textViewEntryFieldModel?.text = newValue
|
textViewEntryFieldModel?.text = newValue
|
||||||
@ -186,29 +183,37 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Validates the text of the entry field.
|
/// Validates the text of the entry field.
|
||||||
@objc public func validateTextView() {
|
@objc public override func validateText() {
|
||||||
text = textView.text
|
text = textView.text
|
||||||
if let isValid = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) {
|
super.validateText()
|
||||||
self.isValid = isValid
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes on UITextView.textDidBeginEditingNotification
|
/// Executes on UITextView.textDidBeginEditingNotification
|
||||||
@objc func startEditing() {
|
@objc override func startEditing() {
|
||||||
isSelected = true
|
super.startEditing()
|
||||||
_ = textView.becomeFirstResponder()
|
_ = textView.becomeFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes on UITextView.textDidChangeNotification (each character entry)
|
/// Executes on UITextView.textDidChangeNotification (each character entry)
|
||||||
@objc func valueChanged() {
|
@objc override func valueChanged() {
|
||||||
guard validateEachCharacter else { return }
|
super.valueChanged()
|
||||||
validateTextView()
|
validateText()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes on UITextView.textDidEndEditingNotification
|
/// Executes on UITextView.textDidEndEditingNotification
|
||||||
@objc func endInputing() {
|
@objc override func endInputing() {
|
||||||
resignFirstResponder()
|
super.endInputing()
|
||||||
isSelected = false
|
|
||||||
|
// Don't show error till user starts typing.
|
||||||
|
guard text?.count ?? 0 != 0 else {
|
||||||
|
showError = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if let isValid = textViewEntryFieldModel?.isValid {
|
||||||
|
self.isValid = isValid
|
||||||
|
}
|
||||||
|
|
||||||
showError = !isValid
|
showError = !isValid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,11 @@ public class RuleEqualsIgnoreCaseModel: RulesProtocol {
|
|||||||
if let fieldValue = formField.formFieldValue() as? String,
|
if let fieldValue = formField.formFieldValue() as? String,
|
||||||
compareString.caseInsensitiveCompare(fieldValue) == .orderedSame {
|
compareString.caseInsensitiveCompare(fieldValue) == .orderedSame {
|
||||||
valid = true
|
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)
|
(formField as? FormRuleWatcherFieldProtocol)?.setValidity(valid, rule: self)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user