Merge branch 'develop' into 'release/7_7_0'

Develop

See merge request BPHV_MIPS/mvm_core_ui!446
This commit is contained in:
Suresh, Kamlesh Jain 2020-05-19 20:31:54 -04:00
commit 7e4deb6d97
6 changed files with 113 additions and 67 deletions

View File

@ -322,7 +322,7 @@ import UIKit
@objc override open func resignFirstResponder() -> Bool {
if validateWhenDoneEditing {
validateTextField()
validateText()
}
selectedDigitBox?.isSelected = false
@ -440,7 +440,7 @@ extension DigitEntryField {
selectedDigitBox = nil
if !switchFieldsAutomatically && validateWhenDoneEditing {
validateTextField()
validateText()
}
proprietorTextDelegate?.textFieldDidEndEditing?(textField)

View File

@ -49,6 +49,9 @@ import UIKit
public var isValid: Bool = false
/// Validate on each entry in the textField. Default: true
public var validateEachCharacter: Bool = true
//--------------------------------------------------
// MARK: - Computed Properties
//--------------------------------------------------
@ -229,6 +232,48 @@ import UIKit
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
//--------------------------------------------------
@ -255,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

View File

@ -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?()
}
//--------------------------------------------------

View File

@ -51,9 +51,6 @@ import UIKit
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
public var validateWhenDoneEditing: Bool = true
@ -226,7 +223,7 @@ import UIKit
@discardableResult
@objc override open func resignFirstResponder() -> Bool {
if validateWhenDoneEditing {
validateTextField()
validateText()
}
textField.resignFirstResponder()
isSelected = false
@ -234,56 +231,37 @@ import UIKit
}
/// Validates the text of the entry field.
@objc public func validateTextField() {
@objc public override func validateText() {
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
@objc func startEditing() {
isSelected = true
@objc override func startEditing() {
super.startEditing()
textField.becomeFirstResponder()
}
/// Executes on UITextField.textDidChangeNotification (each character entry)
@objc func valueChanged() {
guard validateEachCharacter else { return }
isSelected = true
validateTextField()
@objc override func valueChanged() {
super.valueChanged()
validateText()
}
/// Executes on UITextField.textDidEndEditingNotification
@objc func endInputing() {
resignFirstResponder()
@objc override func endInputing() {
super.endInputing()
// Don't show error till user starts typing.
guard text?.count ?? 0 != 0 else {
showError = false
return
}
if let isValid = (model as? TextEntryFieldModel)?.isValid {
if let isValid = textEntryFieldModel?.isValid {
self.isValid = 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
//--------------------------------------------------
@ -320,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

View File

@ -24,9 +24,6 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
// MARK: - Properties
//--------------------------------------------------
/// Validate on each entry in the textView. Default: true
public var validateEachCharacter: Bool = true
private var observingForChange: Bool = false
//--------------------------------------------------
@ -71,7 +68,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
/// The text of this textView.
open override var text: String? {
get { return textView.text }
get { return textViewEntryFieldModel?.text }
set {
textView.text = newValue
textViewEntryFieldModel?.text = newValue
@ -186,29 +183,37 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
//--------------------------------------------------
/// Validates the text of the entry field.
@objc public func validateTextView() {
@objc public override func validateText() {
text = textView.text
if let isValid = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) {
self.isValid = isValid
}
super.validateText()
}
/// Executes on UITextView.textDidBeginEditingNotification
@objc func startEditing() {
isSelected = true
@objc override func startEditing() {
super.startEditing()
_ = textView.becomeFirstResponder()
}
/// Executes on UITextView.textDidChangeNotification (each character entry)
@objc func valueChanged() {
guard validateEachCharacter else { return }
validateTextView()
@objc override func valueChanged() {
super.valueChanged()
validateText()
}
/// Executes on UITextView.textDidEndEditingNotification
@objc func endInputing() {
resignFirstResponder()
isSelected = false
@objc override func endInputing() {
super.endInputing()
// 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
}

View File

@ -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)