added internalShowError/internalErrorText so that you won't overwrite external validators
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
a4582f11a5
commit
4df689b275
@ -153,27 +153,30 @@ open class EntryFieldBase: Control, Changeable {
|
||||
/// Whether not to show the error.
|
||||
open var showError: Bool = false { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// Whether or not to show the internal error
|
||||
internal var showInternalError: Bool = false { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// Override UIControl state to add the .error state if showError is true.
|
||||
open override var state: UIControl.State {
|
||||
get {
|
||||
var state = super.state
|
||||
if showError {
|
||||
if showError || showInternalError {
|
||||
state.insert(.error)
|
||||
}
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
private var _errorText: String?
|
||||
|
||||
|
||||
open var errorText: String? {
|
||||
get { return _errorText }
|
||||
set {
|
||||
if let newValue {
|
||||
_errorText = newValue
|
||||
} else {
|
||||
_errorText = nil
|
||||
}
|
||||
didSet {
|
||||
updateContainerView()
|
||||
updateErrorLabel()
|
||||
setNeedsUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
internal var internalErrorText: String? {
|
||||
didSet {
|
||||
updateContainerView()
|
||||
updateErrorLabel()
|
||||
setNeedsUpdate()
|
||||
@ -365,7 +368,16 @@ open class EntryFieldBase: Control, Changeable {
|
||||
}
|
||||
|
||||
open func updateErrorLabel(){
|
||||
if showError, let errorText {
|
||||
if showError, showInternalError, let errorText, let internalErrorText {
|
||||
errorLabel.text = [internalErrorText, errorText].joined(separator: "\n")
|
||||
errorLabel.surface = surface
|
||||
errorLabel.isEnabled = isEnabled
|
||||
errorLabel.isHidden = false
|
||||
icon.name = .error
|
||||
icon.color = VDSColor.paletteBlack
|
||||
icon.surface = surface
|
||||
icon.isHidden = !isEnabled
|
||||
} else if showError, let errorText {
|
||||
errorLabel.text = errorText
|
||||
errorLabel.surface = surface
|
||||
errorLabel.isEnabled = isEnabled
|
||||
@ -374,6 +386,15 @@ open class EntryFieldBase: Control, Changeable {
|
||||
icon.color = VDSColor.paletteBlack
|
||||
icon.surface = surface
|
||||
icon.isHidden = !isEnabled
|
||||
} else if showInternalError, let internalErrorText {
|
||||
errorLabel.text = internalErrorText
|
||||
errorLabel.surface = surface
|
||||
errorLabel.isEnabled = isEnabled
|
||||
errorLabel.isHidden = false
|
||||
icon.name = .error
|
||||
icon.color = VDSColor.paletteBlack
|
||||
icon.surface = surface
|
||||
icon.isHidden = !isEnabled
|
||||
} else {
|
||||
icon.isHidden = true
|
||||
errorLabel.isHidden = true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user