refactored more code
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c0b59694f2
commit
65ce18d083
@ -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() } }
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user