diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 478bc7db..7a22a3a6 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -21,8 +21,32 @@ public class RadioButton: RadioButtonBase{ } } -public class RadioButtonGroupModel: SelectorGroupModelBase {} -public class RadioButtonGroup: SelectorGroupBase {} +public struct RadioButtonGroupModel: SelectorGroupModel{ + public typealias SelectorType = DefaultRadioButtonModel + public var inputId: String? + public var value: AnyHashable? + public var surface: Surface = .light + public var disabled: Bool = false + public var selectors: [SelectorType] + public init() { selectors = [] } + public init(selectors: [SelectorType]){ + self.selectors = selectors + } +} + +public class RadioButtonGroup: SelectorGroup { + public override func didSelect(selector: RadioButton) { + //deselect current selector + self.selectedView?.isSelected = false +// print("Selected Selector: \(inputId): \(selector.model.selected)") + selector.isSelected = true + self.selectedView = selector +// print("Selected Selector: \(inputId): \(selector.model.selected)") +// for selectorModel in viewModel.selectors { +// print("Cached Selector: \(selectorModel.inputId): \(selectorModel.selected)") +// } + } +} open class RadioButtonBase: SelectorBase { diff --git a/VDS/Components/SelectorBase/SelectorGroup.swift b/VDS/Components/SelectorBase/SelectorGroup.swift index 9f6c063a..ddba6530 100644 --- a/VDS/Components/SelectorBase/SelectorGroup.swift +++ b/VDS/Components/SelectorBase/SelectorGroup.swift @@ -9,24 +9,25 @@ import Foundation import UIKit -public protocol SelectorGroupModel: Modelable, FormFieldable { +public protocol SelectorGroupModel: Modelable, FormFieldable { associatedtype SelectorType: SelectorModel var selectors: [SelectorType] { get set } } -open class SelectorGroupModelBase: SelectorGroupModel{ +public struct DefaultSelectorGroupModel: SelectorGroupModel{ public var inputId: String? public var value: AnyHashable? public var surface: Surface = .light public var disabled: Bool = false public var selectors: [SelectorType] - required public init() { selectors = [] } + public init() { selectors = [] } public init(selectors: [SelectorType]){ self.selectors = selectors } } -open class SelectorGroupBase>: View>, Changable { +open class SelectorGroup, SelectorHandlerType: SelectorBase>: View, Changable { + public var selectorViews: [SelectorHandlerType] = [] public var selectedView: SelectorHandlerType? public var onChange: Blocks.ActionBlock? @@ -86,6 +87,7 @@ open class SelectorGroupBase SelectorHandlerType? { return selectorViews.first(where: { existingSelectorView in return existingSelectorView.model.inputId == inputId @@ -101,17 +103,18 @@ open class SelectorGroupBase