Merge branch 'genericEntryField' into vasavk/inputStepper

# Conflicts:
#	VDS/Components/InputStepper/InputStepper.swift

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-08-02 16:38:24 -05:00
commit ce3d9e6e22
7 changed files with 19 additions and 20 deletions

View File

@ -6,7 +6,7 @@ import Combine
/// A dropdown select is an expandable menu of predefined options that allows a customer to make a single selection.
@objcMembers
@objc(VDSDatePicker)
open class DatePicker: EntryFieldBase {
open class DatePicker: EntryFieldBase<String> {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------

View File

@ -13,7 +13,7 @@ import Combine
/// A dropdown select is an expandable menu of predefined options that allows a customer to make a single selection.
@objcMembers
@objc(VDSDropdownSelect)
open class DropdownSelect: EntryFieldBase {
open class DropdownSelect: EntryFieldBase<String> {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------

View File

@ -11,10 +11,7 @@ import VDSCoreTokens
import Combine
/// Base Class used to build out a Input controls.
@objcMembers
@objc(VDSEntryField)
open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
open class EntryFieldBase<ValueType>: Control, Changeable, FormFieldInternalValidatable {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
@ -229,11 +226,11 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
open var inputId: String? { didSet { setNeedsUpdate() } }
/// The text of this textField.
open var value: String? {
open var value: ValueType? {
get { fatalError("must be read from subclass")}
}
open var defaultValue: AnyHashable? { didSet { setNeedsUpdate() } }
open var defaultValue: ValueType? { didSet { setNeedsUpdate() } }
open var isRequired: Bool = false { didSet { setNeedsUpdate() } }
@ -245,7 +242,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
}
}
open var rules = [AnyRule<String>]()
open var rules = [AnyRule<ValueType>]()
open var accessibilityHintText: String = "Double tap to open"
@ -342,8 +339,8 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
}
containerView.bridge_accessibilityValueBlock = { [weak self] in
guard let self else { return "" }
return value
guard let self, let value else { return "" }
return "\(value)"
}
statusIcon.bridge_accessibilityLabelBlock = { [weak self] in
@ -523,8 +520,8 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
//--------------------------------------------------
internal func updateRules() {
rules.removeAll()
if isRequired && useRequiredRule {
let rule = RequiredRule()
if isRequired && useRequiredRule && ValueType.self == String.self {
let rule = RequiredRule<ValueType>()
if let errorText, !errorText.isEmpty {
rule.errorMessage = errorText
} else if let labelText{

View File

@ -15,7 +15,7 @@ import Combine
/// dates and security codes in their correct formats.
@objcMembers
@objc(VDSInputField)
open class InputField: EntryFieldBase {
open class InputField: EntryFieldBase<String> {
//--------------------------------------------------
// MARK: - Initializers

View File

@ -7,12 +7,14 @@
import Foundation
class RequiredRule: Rule {
class RequiredRule<ValueType>: Rule {
var maxLength: Int?
var errorMessage: String = "This field is required."
func isValid(value: String?) -> Bool {
guard let value, !value.isEmpty, value.count > 0 else { return false }
func isValid(value: ValueType?) -> Bool {
guard let value,
!"\(value)".isEmpty,
"\(value)".count > 0 else { return false }
return true
}
}

View File

@ -14,7 +14,7 @@ import Combine
/// Use a text area when you want customers to enter text thats longer than a single line.
@objcMembers
@objc(VDSTextArea)
open class TextArea: EntryFieldBase {
open class TextArea: EntryFieldBase<String> {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------

View File

@ -8,7 +8,7 @@
import Foundation
/// Protocol used for a FormField object.
public protocol FormFieldable {
public protocol FormFieldable<ValueType> {
associatedtype ValueType = AnyHashable
/// Unique Id for the Form Field object within a Form.
@ -19,7 +19,7 @@ public protocol FormFieldable {
}
/// Protocol for FormFieldable that require internal validation.
public protocol FormFieldInternalValidatable: FormFieldable, Errorable {
public protocol FormFieldInternalValidatable<ValueType>: FormFieldable, Errorable {
/// Rules that drive the validator
var rules: [AnyRule<ValueType>] { get set }