added uuid
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
2e3c63ad5c
commit
15d71e41dd
@ -16,7 +16,7 @@ extension CheckboxModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public struct DefaultCheckboxModel: CheckboxModel {
|
public struct DefaultCheckboxModel: CheckboxModel {
|
||||||
public var id: String?
|
public var id: UUID = UUID()
|
||||||
public var selected: Bool = false
|
public var selected: Bool = false
|
||||||
|
|
||||||
public var labelText: String?
|
public var labelText: String?
|
||||||
|
|||||||
@ -23,6 +23,7 @@ public class RadioButton: RadioButtonBase<DefaultRadioButtonModel>{
|
|||||||
|
|
||||||
public struct RadioButtonGroupModel: SelectorGroupModel{
|
public struct RadioButtonGroupModel: SelectorGroupModel{
|
||||||
public typealias SelectorType = DefaultRadioButtonModel
|
public typealias SelectorType = DefaultRadioButtonModel
|
||||||
|
public var id: UUID = UUID()
|
||||||
public var inputId: String?
|
public var inputId: String?
|
||||||
public var value: AnyHashable?
|
public var value: AnyHashable?
|
||||||
public var surface: Surface = .light
|
public var surface: Surface = .light
|
||||||
@ -36,19 +37,6 @@ public struct RadioButtonGroupModel: SelectorGroupModel{
|
|||||||
|
|
||||||
public class RadioButtonGroup: SelectorGroup<DefaultRadioButtonModel, RadioButtonGroupModel, RadioButton> {
|
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) {
|
public override func didSelect(selected: DefaultRadioButtonModel) {
|
||||||
for selectorModel in model.selectors {
|
for selectorModel in model.selectors {
|
||||||
print("Pre Cached Selector: \(selectorModel.inputId): \(selectorModel.selected)")
|
print("Pre Cached Selector: \(selectorModel.inputId): \(selectorModel.selected)")
|
||||||
|
|||||||
@ -17,7 +17,7 @@ extension RadioButtonModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public struct DefaultRadioButtonModel: RadioButtonModel {
|
public struct DefaultRadioButtonModel: RadioButtonModel {
|
||||||
public var id: String?
|
public var id: UUID = UUID()
|
||||||
public var selected: Bool = false
|
public var selected: Bool = false
|
||||||
|
|
||||||
public var labelText: String?
|
public var labelText: String?
|
||||||
|
|||||||
@ -69,7 +69,7 @@ open class SelectorBase<ModelType: SelectorModel>: Control<ModelType>, Changable
|
|||||||
public var onChange: Blocks.ActionBlock?
|
public var onChange: Blocks.ActionBlock?
|
||||||
|
|
||||||
@Proxy(\.model.id)
|
@Proxy(\.model.id)
|
||||||
open var id: String?
|
open var id: UUID
|
||||||
|
|
||||||
//can't bind to @Proxy
|
//can't bind to @Proxy
|
||||||
open override var isSelected: Bool {
|
open override var isSelected: Bool {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public protocol SelectorGroupModel<SelectorType>: Modelable, FormFieldable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public struct DefaultSelectorGroupModel<SelectorType: SelectorModel>: SelectorGroupModel {
|
public struct DefaultSelectorGroupModel<SelectorType: SelectorModel>: SelectorGroupModel {
|
||||||
|
public var id: UUID = UUID()
|
||||||
public var inputId: String?
|
public var inputId: String?
|
||||||
public var value: AnyHashable?
|
public var value: AnyHashable?
|
||||||
public var surface: Surface = .light
|
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) { }
|
open func didSelect(selected: SelectorType) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,6 @@ public protocol Selectable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public protocol SelectorModel: Modelable, FormFieldable, Errorable, DataTrackable, Accessable, Selectable {
|
public protocol SelectorModel: Modelable, FormFieldable, Errorable, DataTrackable, Accessable, Selectable {
|
||||||
var id: String? { get set }
|
|
||||||
var labelText: String? { get set }
|
var labelText: String? { get set }
|
||||||
var labelTextAttributes: [LabelAttributeModel]? { get set }
|
var labelTextAttributes: [LabelAttributeModel]? { get set }
|
||||||
var childText: String? { get set }
|
var childText: String? { get set }
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public protocol ToggleModel: Modelable, FormFieldable, DataTrackable, Accessable, Labelable, BinaryColorable {
|
public protocol ToggleModel: Modelable, FormFieldable, DataTrackable, Accessable, Labelable, BinaryColorable {
|
||||||
var id: String? { get set }
|
|
||||||
var showText: Bool { get set }
|
var showText: Bool { get set }
|
||||||
var on: Bool { get set }
|
var on: Bool { get set }
|
||||||
var offText: String { get set }
|
var offText: String { get set }
|
||||||
@ -38,7 +37,7 @@ extension ToggleModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public struct DefaultToggleModel: ToggleModel {
|
public struct DefaultToggleModel: ToggleModel {
|
||||||
public var id: String?
|
public var id: UUID = UUID()
|
||||||
public var on: Bool = false
|
public var on: Bool = false
|
||||||
public var showText: Bool = false
|
public var showText: Bool = false
|
||||||
public var offText: String = "Off"
|
public var offText: String = "Off"
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public protocol FormFieldable {
|
public protocol FormFieldable {
|
||||||
|
var id: UUID { get set }
|
||||||
var inputId: String? { get set }
|
var inputId: String? { get set }
|
||||||
var value: AnyHashable? { get set }
|
var value: AnyHashable? { get set }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user