updated checkbox/label
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
568ab2e5e5
commit
a84f502a0e
@ -142,7 +142,7 @@ import VDS
|
|||||||
self.isSelected = isSelected
|
self.isSelected = isSelected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Molecular
|
// MARK: - Molecular
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -179,7 +179,10 @@ import VDS
|
|||||||
viewModel.updateUI = {
|
viewModel.updateUI = {
|
||||||
MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
|
MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
let isValid = viewModel.isValid ?? true
|
||||||
|
showError = !isValid
|
||||||
isEnabled = viewModel.enabled
|
isEnabled = viewModel.enabled
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,46 +14,29 @@ import VDS
|
|||||||
var selected: Bool { get set }
|
var selected: Bool { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
@objcMembers public class CheckboxModel: MoleculeModelProtocol, SelectableMoleculeModelProtocol, FormFieldProtocol, UIUpdatableModelProtocol {
|
@objcMembers public class CheckboxModel: FormFieldModel, SelectableMoleculeModelProtocol{
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
public static override var identifier: String { "checkbox" }
|
||||||
public static var identifier: String = "checkbox"
|
|
||||||
public var id: String = UUID().uuidString
|
|
||||||
public var backgroundColor: Color?
|
|
||||||
public var accessibilityIdentifier: String?
|
|
||||||
public var selected: Bool = false
|
public var selected: Bool = false
|
||||||
public var enabled: Bool = true
|
|
||||||
public var readOnly: Bool = false
|
|
||||||
public var animated: Bool = true
|
public var animated: Bool = true
|
||||||
public var inverted: Bool = false
|
public var inverted: Bool = false
|
||||||
public var action: ActionModelProtocol?
|
public var action: ActionModelProtocol?
|
||||||
public var offAction: ActionModelProtocol?
|
public var offAction: ActionModelProtocol?
|
||||||
|
|
||||||
public var surface: Surface { inverted ? .dark : .light }
|
public var surface: Surface { inverted ? .dark : .light }
|
||||||
public var fieldKey: String?
|
|
||||||
public var groupName: String = FormValidator.defaultGroupName
|
|
||||||
public var baseValue: AnyHashable?
|
|
||||||
public var updateUI: ActionBlock?
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Keys
|
// MARK: - Keys
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case id
|
|
||||||
case moleculeName
|
|
||||||
case accessibilityIdentifier
|
|
||||||
case checked
|
case checked
|
||||||
case enabled
|
|
||||||
case readOnly
|
|
||||||
case inverted
|
case inverted
|
||||||
case animated
|
case animated
|
||||||
case action
|
case action
|
||||||
case fieldKey
|
|
||||||
case groupName
|
|
||||||
case offAction
|
case offAction
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,16 +44,17 @@ import VDS
|
|||||||
// MARK: - Form Validation
|
// MARK: - Form Validation
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func formFieldValue() -> AnyHashable? {
|
open override func formFieldValue() -> AnyHashable? {
|
||||||
guard enabled else { return nil }
|
guard enabled else { return nil }
|
||||||
return selected
|
return selected
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
open override func setValidity(_ valid: Bool, errorMessage: String?) {
|
||||||
// MARK: - Server Value
|
if let ruleErrorMessage = errorMessage, fieldKey != nil {
|
||||||
//--------------------------------------------------
|
self.errorMessage = ruleErrorMessage
|
||||||
open func formFieldServerValue() -> AnyHashable? {
|
}
|
||||||
return formFieldValue()
|
isValid = valid
|
||||||
|
updateUI?()
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -78,7 +62,8 @@ import VDS
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public init(isChecked: Bool = false) {
|
public init(isChecked: Bool = false) {
|
||||||
self.selected = isChecked
|
super.init()
|
||||||
|
selected = isChecked
|
||||||
baseValue = isChecked
|
baseValue = isChecked
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,12 +72,9 @@ import VDS
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
|
try super.init(from: decoder)
|
||||||
|
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
|
||||||
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
|
|
||||||
|
|
||||||
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
|
|
||||||
|
|
||||||
if let checked = try typeContainer.decodeIfPresent(Bool.self, forKey: .checked) {
|
if let checked = try typeContainer.decodeIfPresent(Bool.self, forKey: .checked) {
|
||||||
self.selected = checked
|
self.selected = checked
|
||||||
}
|
}
|
||||||
@ -107,31 +89,18 @@ import VDS
|
|||||||
self.inverted = inverted
|
self.inverted = inverted
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) ?? true
|
|
||||||
readOnly = try typeContainer.decodeIfPresent(Bool.self, forKey: .readOnly) ?? false
|
|
||||||
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
|
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
|
||||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
|
||||||
|
|
||||||
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
|
|
||||||
self.groupName = groupName
|
|
||||||
}
|
|
||||||
offAction = try typeContainer.decodeModelIfPresent(codingKey: .offAction)
|
offAction = try typeContainer.decodeModelIfPresent(codingKey: .offAction)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(id, forKey: .id)
|
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
|
||||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
|
||||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
|
||||||
try container.encode(selected, forKey: .checked)
|
try container.encode(selected, forKey: .checked)
|
||||||
try container.encode(inverted, forKey: .inverted)
|
try container.encode(inverted, forKey: .inverted)
|
||||||
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
|
|
||||||
try container.encodeIfPresent(animated, forKey: .animated)
|
try container.encodeIfPresent(animated, forKey: .animated)
|
||||||
try container.encode(enabled, forKey: .enabled)
|
|
||||||
try container.encode(readOnly, forKey: .readOnly)
|
|
||||||
try container.encodeModelIfPresent(action, forKey: .action)
|
try container.encodeModelIfPresent(action, forKey: .action)
|
||||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
|
||||||
try container.encodeModelIfPresent(offAction, forKey: .offAction)
|
try container.encodeModelIfPresent(offAction, forKey: .offAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,6 +83,9 @@ import VDS
|
|||||||
viewModel.checkbox.updateUI = {
|
viewModel.checkbox.updateUI = {
|
||||||
MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
|
MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
let isValid = viewModel.checkbox.isValid ?? true
|
||||||
|
showError = !isValid
|
||||||
|
errorText = viewModel.checkbox.errorMessage
|
||||||
isEnabled = viewModel.checkbox.enabled
|
isEnabled = viewModel.checkbox.enabled
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,9 +25,9 @@ public enum CheckboxPosition: String, Codable {
|
|||||||
public var checkbox: CheckboxModel
|
public var checkbox: CheckboxModel
|
||||||
public var label: LabelModel
|
public var label: LabelModel
|
||||||
public var subtitle: LabelModel?
|
public var subtitle: LabelModel?
|
||||||
public var inverted: Bool = false
|
public var inverted: Bool? = false
|
||||||
public var surface: Surface { inverted ? .dark : .light }
|
public var surface: Surface { inverted ?? false ? .dark : .light }
|
||||||
|
|
||||||
public var children: [MoleculeModelProtocol] {
|
public var children: [MoleculeModelProtocol] {
|
||||||
guard let subtitle else { return [checkbox, label] }
|
guard let subtitle else { return [checkbox, label] }
|
||||||
return [checkbox, label, subtitle]
|
return [checkbox, label, subtitle]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user