updated input validators
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
1813661f7d
commit
06d56fd70e
@ -179,19 +179,14 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
||||
}
|
||||
}
|
||||
|
||||
open var errorText: String? {
|
||||
didSet {
|
||||
updateContainerView()
|
||||
updateErrorLabel()
|
||||
setNeedsUpdate()
|
||||
}
|
||||
}
|
||||
open var errorText: String? { didSet { setNeedsUpdate() } }
|
||||
|
||||
open var internalErrorText: String? {
|
||||
didSet {
|
||||
updateContainerView()
|
||||
updateErrorLabel()
|
||||
setNeedsUpdate()
|
||||
guard let validator, !validator.isValid else { return nil }
|
||||
if let errorText, !errorText.isEmpty {
|
||||
return errorText
|
||||
} else {
|
||||
return validator.errorMessage
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,28 +308,15 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
||||
super.updateView()
|
||||
updateRules()
|
||||
validator = FormFieldValidator<EntryFieldBase>(field: self, rules: rules)
|
||||
|
||||
validator?.validate()
|
||||
|
||||
updateContainerView()
|
||||
updateTitleLabel()
|
||||
updateErrorLabel()
|
||||
updateHelperLabel()
|
||||
|
||||
backgroundColor = surface.color
|
||||
|
||||
if let validator {
|
||||
validator.validate()
|
||||
if validator.isValid {
|
||||
internalErrorText = nil
|
||||
} else {
|
||||
if let errorText, errorText.isEmpty {
|
||||
internalErrorText = errorText
|
||||
} else {
|
||||
internalErrorText = validator.errorMessage
|
||||
}
|
||||
}
|
||||
} else {
|
||||
internalErrorText = nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -364,7 +346,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
||||
rules.removeAll()
|
||||
if self.required {
|
||||
let rule = RequiredRule()
|
||||
if let errorText {
|
||||
if let errorText, !errorText.isEmpty {
|
||||
rule.errorMessage = errorText
|
||||
} else if let labelText{
|
||||
rule.errorMessage = "You must enter a \(labelText)"
|
||||
|
||||
@ -128,7 +128,7 @@ open class InputField: EntryFieldBase {
|
||||
if showSuccess {
|
||||
state.insert(.success)
|
||||
|
||||
} else if textField.isFirstResponder && !showError && !hasInternalError {
|
||||
} else if textField.isFirstResponder {
|
||||
state.insert(.focused)
|
||||
}
|
||||
|
||||
@ -218,7 +218,11 @@ open class InputField: EntryFieldBase {
|
||||
|
||||
textField.isEnabled = isEnabled
|
||||
textField.textColor = textFieldTextColorConfiguration.getColor(self)
|
||||
|
||||
}
|
||||
|
||||
open override func updateErrorLabel() {
|
||||
super.updateErrorLabel()
|
||||
|
||||
//show error or success
|
||||
if showError, let _ = errorText {
|
||||
successLabel.isHidden = true
|
||||
@ -234,11 +238,10 @@ open class InputField: EntryFieldBase {
|
||||
statusIcon.surface = surface
|
||||
statusIcon.isHidden = !isEnabled
|
||||
} else {
|
||||
statusIcon.isHidden = true
|
||||
successLabel.isHidden = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
open override func updateHelperLabel(){
|
||||
//remove first
|
||||
helperLabel.removeFromSuperview()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user