added uuid

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-08-10 16:25:56 -05:00
parent 2e3c63ad5c
commit 15d71e41dd
8 changed files with 15 additions and 19 deletions

View File

@ -16,7 +16,7 @@ extension CheckboxModel {
}
public struct DefaultCheckboxModel: CheckboxModel {
public var id: String?
public var id: UUID = UUID()
public var selected: Bool = false
public var labelText: String?

View File

@ -23,6 +23,7 @@ public class RadioButton: RadioButtonBase<DefaultRadioButtonModel>{
public struct RadioButtonGroupModel: SelectorGroupModel{
public typealias SelectorType = DefaultRadioButtonModel
public var id: UUID = UUID()
public var inputId: String?
public var value: AnyHashable?
public var surface: Surface = .light
@ -36,19 +37,6 @@ public struct RadioButtonGroupModel: SelectorGroupModel{
public class RadioButtonGroup: SelectorGroup<DefaultRadioButtonModel, RadioButtonGroupModel, RadioButton> {
private func replace(viewModel: DefaultRadioButtonModel){
guard let viewModelInputId = viewModel.inputId else { return }
if let index = model.selectors.firstIndex(where: { radio in
if let cachedInputId = radio.inputId {
return cachedInputId == viewModelInputId
} else {
return false
}
}) {
model.selectors[index] = viewModel
}
}
public override func didSelect(selected: DefaultRadioButtonModel) {
for selectorModel in model.selectors {
print("Pre Cached Selector: \(selectorModel.inputId): \(selectorModel.selected)")

View File

@ -17,7 +17,7 @@ extension RadioButtonModel {
}
public struct DefaultRadioButtonModel: RadioButtonModel {
public var id: String?
public var id: UUID = UUID()
public var selected: Bool = false
public var labelText: String?

View File

@ -69,7 +69,7 @@ open class SelectorBase<ModelType: SelectorModel>: Control<ModelType>, Changable
public var onChange: Blocks.ActionBlock?
@Proxy(\.model.id)
open var id: String?
open var id: UUID
//can't bind to @Proxy
open override var isSelected: Bool {

View File

@ -15,6 +15,7 @@ public protocol SelectorGroupModel<SelectorType>: Modelable, FormFieldable {
}
public struct DefaultSelectorGroupModel<SelectorType: SelectorModel>: SelectorGroupModel {
public var id: UUID = UUID()
public var inputId: String?
public var value: AnyHashable?
public var surface: Surface = .light
@ -112,5 +113,13 @@ open class SelectorGroup<SelectorType, SelectorGroupType: SelectorGroupModel<Sel
}
public func replace(viewModel: SelectorType){
if let index = model.selectors.firstIndex(where: { element in
return element.id == viewModel.id
}) {
model.selectors[index] = viewModel
}
}
open func didSelect(selected: SelectorType) { }
}

View File

@ -12,7 +12,6 @@ public protocol Selectable {
}
public protocol SelectorModel: Modelable, FormFieldable, Errorable, DataTrackable, Accessable, Selectable {
var id: String? { get set }
var labelText: String? { get set }
var labelTextAttributes: [LabelAttributeModel]? { get set }
var childText: String? { get set }

View File

@ -9,7 +9,6 @@ import Foundation
import UIKit
public protocol ToggleModel: Modelable, FormFieldable, DataTrackable, Accessable, Labelable, BinaryColorable {
var id: String? { get set }
var showText: Bool { get set }
var on: Bool { get set }
var offText: String { get set }
@ -38,7 +37,7 @@ extension ToggleModel {
}
public struct DefaultToggleModel: ToggleModel {
public var id: String?
public var id: UUID = UUID()
public var on: Bool = false
public var showText: Bool = false
public var offText: String = "Off"

View File

@ -8,6 +8,7 @@
import Foundation
public protocol FormFieldable {
var id: UUID { get set }
var inputId: String? { get set }
var value: AnyHashable? { get set }
}