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:
Matt Bruce 2024-02-29 12:14:12 -06:00
parent a4582f11a5
commit 4df689b275

View File

@ -153,27 +153,30 @@ open class EntryFieldBase: Control, Changeable {
/// Whether not to show the error. /// Whether not to show the error.
open var showError: Bool = false { didSet { setNeedsUpdate() } } 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. /// Override UIControl state to add the .error state if showError is true.
open override var state: UIControl.State { open override var state: UIControl.State {
get { get {
var state = super.state var state = super.state
if showError { if showError || showInternalError {
state.insert(.error) state.insert(.error)
} }
return state return state
} }
} }
private var _errorText: String?
open var errorText: String? { open var errorText: String? {
get { return _errorText } didSet {
set { updateContainerView()
if let newValue { updateErrorLabel()
_errorText = newValue setNeedsUpdate()
} else { }
_errorText = nil }
}
internal var internalErrorText: String? {
didSet {
updateContainerView() updateContainerView()
updateErrorLabel() updateErrorLabel()
setNeedsUpdate() setNeedsUpdate()
@ -365,7 +368,16 @@ open class EntryFieldBase: Control, Changeable {
} }
open func updateErrorLabel(){ 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.text = errorText
errorLabel.surface = surface errorLabel.surface = surface
errorLabel.isEnabled = isEnabled errorLabel.isEnabled = isEnabled
@ -374,6 +386,15 @@ open class EntryFieldBase: Control, Changeable {
icon.color = VDSColor.paletteBlack icon.color = VDSColor.paletteBlack
icon.surface = surface icon.surface = surface
icon.isHidden = !isEnabled 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 { } else {
icon.isHidden = true icon.isHidden = true
errorLabel.isHidden = true errorLabel.isHidden = true