added default id to UUID
This commit is contained in:
parent
76b0810905
commit
f8bc4c1167
@ -30,7 +30,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, Accessibilit
|
||||
public var fieldKey: String?
|
||||
public var groupName: String = FormValidator.defaultGroupName
|
||||
public var baseValue: AnyHashable?
|
||||
public var id: String?
|
||||
public var id: String
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
@ -76,9 +76,10 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, Accessibilit
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
|
||||
public init(_ state: Bool) {
|
||||
public init(_ state: Bool, id: String = UUID().uuidString) {
|
||||
self.selected = state
|
||||
baseValue = state
|
||||
self.id = id
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -126,7 +127,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol, Accessibilit
|
||||
}
|
||||
enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) ?? true
|
||||
readOnly = try typeContainer.decodeIfPresent(Bool.self, forKey: .readOnly) ?? false
|
||||
id = try typeContainer.decodeIfPresent(String.self, forKey: .id)
|
||||
id = try typeContainer.decode(forKey: .id, default: { UUID().uuidString }())
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
|
||||
@ -15,5 +15,5 @@ import Foundation
|
||||
|
||||
public protocol AccessibilityElementProtocol: Identifiable {
|
||||
|
||||
var id: String? { get set }
|
||||
var id: String { get set }
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user