removed selected inputId

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-09-08 14:35:09 -05:00
parent 81ed479c87
commit 2148014664
3 changed files with 3 additions and 20 deletions

View File

@ -27,7 +27,7 @@ public class RadioSwatchGroup: RadioSwatchGroupBase<DefaultRadioSwatchGroupModel
label.text = newSelectedModel.text label.text = newSelectedModel.text
replace(viewModel: newSelectedModel) replace(viewModel: newSelectedModel)
selectedInputId = newSelectedModel.inputId sendActions(for: .valueChanged)
} }
} }
@ -37,22 +37,8 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
@Proxy(\.model.selectedInputId)
public var selectedInputId: String? {
didSet {
sendActions(for: .valueChanged)
}
}
public var selectedModel: ModelHandlerType.ModelType? { public var selectedModel: ModelHandlerType.ModelType? {
guard let selectedInputId else { return nil } return model.selectedModel
if let index = model.selectors.firstIndex(where: { element in
return element.inputId == selectedInputId
}) {
return model.selectors[index]
} else {
return nil
}
} }
public var onChange: Blocks.ActionBlock? public var onChange: Blocks.ActionBlock?

View File

@ -28,7 +28,6 @@ public struct DefaultRadioSwatchGroupModel: RadioSwatchGroupModel {
public var surface: Surface = .light public var surface: Surface = .light
public var disabled: Bool = false public var disabled: Bool = false
public var selectors: [SelectorModelType] public var selectors: [SelectorModelType]
public var selectedInputId: String?
public init() { selectors = [] } public init() { selectors = [] }
public init(selectors: [SelectorModelType]){ public init(selectors: [SelectorModelType]){
self.selectors = selectors self.selectors = selectors

View File

@ -15,15 +15,13 @@ public protocol SelectorGroupModelable: Modelable, FormFieldable {
///MARK: Groups that allow single selections ///MARK: Groups that allow single selections
public protocol SelectorGroupSelectedModelable: SelectorGroupModelable { public protocol SelectorGroupSelectedModelable: SelectorGroupModelable {
var selectedInputId: String? { get set }
var selectedModel: SelectorModelType? { get } var selectedModel: SelectorModelType? { get }
} }
extension SelectorGroupSelectedModelable { extension SelectorGroupSelectedModelable {
public var selectedModel: SelectorModelType? { public var selectedModel: SelectorModelType? {
guard let selectedInputId else { return nil }
if let index = selectors.firstIndex(where: { element in if let index = selectors.firstIndex(where: { element in
return element.inputId == selectedInputId return element.selected == true
}) { }) {
return selectors[index] return selectors[index]
} else { } else {