diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index dffbb48d..daae8a66 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -160,13 +160,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { open var showError: Bool = false { didSet { setNeedsUpdate() } } /// FormFieldValidator - internal var validator: (any FormFieldValidatorable)? - - /// Whether or not to show the internal error - open var hasInternalError: Bool { - guard let validator, !showError else { return false } - return !validator.isValid - } + open var validator: (any FormFieldValidatorable)? /// Override UIControl state to add the .error state if showError is true. open override var state: UIControl.State { @@ -180,16 +174,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { } open var errorText: String? { didSet { setNeedsUpdate() } } - - open var internalErrorText: String? { - guard let validator, !validator.isValid else { return nil } - if let errorText, !errorText.isEmpty { - return errorText - } else { - return validator.errorMessage - } - } - + open var tooltipModel: Tooltip.TooltipModel? { didSet { setNeedsUpdate() } } open var transparentBackground: Bool = false { didSet { setNeedsUpdate() } } diff --git a/VDS/Protocols/FormFieldable.swift b/VDS/Protocols/FormFieldable.swift index 83638cf4..8a620765 100644 --- a/VDS/Protocols/FormFieldable.swift +++ b/VDS/Protocols/FormFieldable.swift @@ -19,11 +19,32 @@ public protocol FormFieldable { } /// Protocol for FormFieldable that require internal validation. -public protocol FormFieldInternalValidatable: FormFieldable { +public protocol FormFieldInternalValidatable: FormFieldable, Errorable { /// Is there an internalError var hasInternalError: Bool { get } /// Internal Error Message that will show. var internalErrorText: String? { get } + + var validator: (any FormFieldValidatorable)? { get set } + + func validate() +} + +extension FormFieldInternalValidatable { + /// Whether or not to show the internal error + public var hasInternalError: Bool { + guard let validator, !showError else { return false } + return !validator.isValid + } + + public var internalErrorText: String? { + guard let validator, !validator.isValid else { return nil } + if let errorText, !errorText.isEmpty { + return errorText + } else { + return validator.errorMessage + } + } } /// Struct that will execute the validation.