diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index e32c7ff0..82a385e0 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -11,21 +11,38 @@ import UIKit public class RadioBoxGroup: Control, SelectorGroupSelectedModelHandlerable, Changable { public typealias ModelHandlerType = RadioBox + public func didSelect(_ selectedControl: ModelHandlerType) { + //only changes local model in control, + //this is now disconnected from the parent model + for (index, control) in selectorViews.enumerated() { + //only change the old and new + if control == selectedControl { + let updated = model.selectors[index].copyWith { + $0.selected = true + } + model.selectors[index] = updated + + } else if control.isSelected { + let updated = model.selectors[index].copyWith { + $0.selected = false + } + model.selectors[index] = updated + + } + } + + if hasError { + hasError = false + } + sendActions(for: .valueChanged) + + } + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- public var selectorViews: [ModelHandlerType] = [] - - @Proxy(\.model.selectedInputId) - public var selectedInputId: String? { - didSet{ - if hasError, selectedInputId != nil { - hasError = false - } - sendActions(for: .valueChanged) - } - } - + public var hasError: Bool { get { model.hasError } set { diff --git a/VDS/Components/RadioBox/RadioBoxGroupModel.swift b/VDS/Components/RadioBox/RadioBoxGroupModel.swift index 49d55b92..f1a1a1c7 100644 --- a/VDS/Components/RadioBox/RadioBoxGroupModel.swift +++ b/VDS/Components/RadioBox/RadioBoxGroupModel.swift @@ -16,7 +16,6 @@ public struct DefaultRadioBoxGroupModel: RadioBoxGroupModel { public var surface: Surface = .light public var disabled: Bool = false public var selectors: [SelectorModelType] - public var selectedInputId: String? public var hasError: Bool = false public var errorText: String? public init() { selectors = [] } diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 8299c88d..4b888209 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -11,26 +11,44 @@ import UIKit public class RadioButtonGroup: Control, SelectorGroupSelectedModelHandlerable, Changable { public typealias ModelHandlerType = RadioButton + public func didSelect(_ selectedControl: ModelHandlerType) { + //only changes local model in control, + //this is now disconnected from the parent model + for (index, control) in selectorViews.enumerated() { + //only change the old and new + if control == selectedControl { + let updated = model.selectors[index].copyWith { + $0.selected = true + } + model.selectors[index] = updated + + } else if control.isSelected { + let updated = model.selectors[index].copyWith { + $0.selected = false + } + model.selectors[index] = updated + + } + } + + if hasError { + hasError = false + } + sendActions(for: .valueChanged) + + } + + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- public var selectorViews: [ModelHandlerType] = [] - - @Proxy(\.model.selectedInputId) - public var selectedInputId: String? { - didSet{ - if hasError, selectedInputId != nil { - hasError = false - } - sendActions(for: .valueChanged) - } - } - + public var hasError: Bool { get { model.hasError } set { var newHasError = newValue - if selectedInputId != nil, newHasError { + if selectedModel != nil, newHasError { newHasError = false } let selectors = model.selectors.compactMap { existing in diff --git a/VDS/Components/RadioButton/RadioButtonGroupModel.swift b/VDS/Components/RadioButton/RadioButtonGroupModel.swift index b449107f..ce79e2a5 100644 --- a/VDS/Components/RadioButton/RadioButtonGroupModel.swift +++ b/VDS/Components/RadioButton/RadioButtonGroupModel.swift @@ -14,7 +14,6 @@ extension RadioButtonGroupModel { } public struct DefaultRadioButtonGroupModel: RadioButtonGroupModel { - public var selectedInputId: String? public typealias SelectorModelType = DefaultRadioButtonModel public var inputId: String? public var value: AnyHashable? diff --git a/VDS/Protocols/SelectorGroupModelHandlerable.swift b/VDS/Protocols/SelectorGroupModelHandlerable.swift index 06b7f5ac..23a790f1 100644 --- a/VDS/Protocols/SelectorGroupModelHandlerable.swift +++ b/VDS/Protocols/SelectorGroupModelHandlerable.swift @@ -101,26 +101,4 @@ extension SelectorGroupSelectedModelHandlerable { return newSelectorView } - - public func didSelect(_ selectedControl: ModelHandlerType) { - //only changes local model in control, - //this is now disconnected from the parent model - for (index, control) in selectorViews.enumerated() { - //only change the old and new - if control == selectedControl { - let updated = model.selectors[index].copyWith { - $0.selected = true - } - model.selectors[index] = updated - - } else if control.isSelected { - let updated = model.selectors[index].copyWith { - $0.selected = false - } - model.selectors[index] = updated - - } - } - - } }