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:
commit
ce3d9e6e22
@ -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.
|
/// A dropdown select is an expandable menu of predefined options that allows a customer to make a single selection.
|
||||||
@objcMembers
|
@objcMembers
|
||||||
@objc(VDSDatePicker)
|
@objc(VDSDatePicker)
|
||||||
open class DatePicker: EntryFieldBase {
|
open class DatePicker: EntryFieldBase<String> {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -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.
|
/// A dropdown select is an expandable menu of predefined options that allows a customer to make a single selection.
|
||||||
@objcMembers
|
@objcMembers
|
||||||
@objc(VDSDropdownSelect)
|
@objc(VDSDropdownSelect)
|
||||||
open class DropdownSelect: EntryFieldBase {
|
open class DropdownSelect: EntryFieldBase<String> {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -11,10 +11,7 @@ import VDSCoreTokens
|
|||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
/// Base Class used to build out a Input controls.
|
/// Base Class used to build out a Input controls.
|
||||||
@objcMembers
|
open class EntryFieldBase<ValueType>: Control, Changeable, FormFieldInternalValidatable {
|
||||||
@objc(VDSEntryField)
|
|
||||||
open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -229,11 +226,11 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|||||||
open var inputId: String? { didSet { setNeedsUpdate() } }
|
open var inputId: String? { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// The text of this textField.
|
/// The text of this textField.
|
||||||
open var value: String? {
|
open var value: ValueType? {
|
||||||
get { fatalError("must be read from subclass")}
|
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() } }
|
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"
|
open var accessibilityHintText: String = "Double tap to open"
|
||||||
|
|
||||||
@ -342,8 +339,8 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
containerView.bridge_accessibilityValueBlock = { [weak self] in
|
containerView.bridge_accessibilityValueBlock = { [weak self] in
|
||||||
guard let self else { return "" }
|
guard let self, let value else { return "" }
|
||||||
return value
|
return "\(value)"
|
||||||
}
|
}
|
||||||
|
|
||||||
statusIcon.bridge_accessibilityLabelBlock = { [weak self] in
|
statusIcon.bridge_accessibilityLabelBlock = { [weak self] in
|
||||||
@ -523,8 +520,8 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
internal func updateRules() {
|
internal func updateRules() {
|
||||||
rules.removeAll()
|
rules.removeAll()
|
||||||
if isRequired && useRequiredRule {
|
if isRequired && useRequiredRule && ValueType.self == String.self {
|
||||||
let rule = RequiredRule()
|
let rule = RequiredRule<ValueType>()
|
||||||
if let errorText, !errorText.isEmpty {
|
if let errorText, !errorText.isEmpty {
|
||||||
rule.errorMessage = errorText
|
rule.errorMessage = errorText
|
||||||
} else if let labelText{
|
} else if let labelText{
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import Combine
|
|||||||
/// dates and security codes in their correct formats.
|
/// dates and security codes in their correct formats.
|
||||||
@objcMembers
|
@objcMembers
|
||||||
@objc(VDSInputField)
|
@objc(VDSInputField)
|
||||||
open class InputField: EntryFieldBase {
|
open class InputField: EntryFieldBase<String> {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
|
|||||||
@ -7,12 +7,14 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class RequiredRule: Rule {
|
class RequiredRule<ValueType>: Rule {
|
||||||
var maxLength: Int?
|
var maxLength: Int?
|
||||||
var errorMessage: String = "This field is required."
|
var errorMessage: String = "This field is required."
|
||||||
|
|
||||||
func isValid(value: String?) -> Bool {
|
func isValid(value: ValueType?) -> Bool {
|
||||||
guard let value, !value.isEmpty, value.count > 0 else { return false }
|
guard let value,
|
||||||
|
!"\(value)".isEmpty,
|
||||||
|
"\(value)".count > 0 else { return false }
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import Combine
|
|||||||
/// Use a text area when you want customers to enter text that’s longer than a single line.
|
/// Use a text area when you want customers to enter text that’s longer than a single line.
|
||||||
@objcMembers
|
@objcMembers
|
||||||
@objc(VDSTextArea)
|
@objc(VDSTextArea)
|
||||||
open class TextArea: EntryFieldBase {
|
open class TextArea: EntryFieldBase<String> {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/// Protocol used for a FormField object.
|
/// Protocol used for a FormField object.
|
||||||
public protocol FormFieldable {
|
public protocol FormFieldable<ValueType> {
|
||||||
associatedtype ValueType = AnyHashable
|
associatedtype ValueType = AnyHashable
|
||||||
|
|
||||||
/// Unique Id for the Form Field object within a Form.
|
/// Unique Id for the Form Field object within a Form.
|
||||||
@ -19,7 +19,7 @@ public protocol FormFieldable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Protocol for FormFieldable that require internal validation.
|
/// Protocol for FormFieldable that require internal validation.
|
||||||
public protocol FormFieldInternalValidatable: FormFieldable, Errorable {
|
public protocol FormFieldInternalValidatable<ValueType>: FormFieldable, Errorable {
|
||||||
/// Rules that drive the validator
|
/// Rules that drive the validator
|
||||||
var rules: [AnyRule<ValueType>] { get set }
|
var rules: [AnyRule<ValueType>] { get set }
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user