From 4ae6a393d316188e65a376fd54b5396c197f6c04 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 6 Mar 2020 14:20:58 -0500 Subject: [PATCH] key update --- MVMCoreUI/Atoms/Views/Checkbox.swift | 68 ++--------------------- MVMCoreUI/Atoms/Views/CheckboxModel.swift | 35 ++++++------ 2 files changed, 20 insertions(+), 83 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index fd186d7e..e12fae69 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -19,9 +19,8 @@ import MVMCore public var sizeObject: MFSizeObject? = MFSizeObject(standardSize: Checkbox.defaultHeightWidth, standardiPadPortraitSize: Checkbox.defaultHeightWidth + 6.0) // Form Validation - var isRequired = false var fieldKey: String? - var fieldValue: String? + var fieldValue: JSONValue? var groupName: String? var delegateObject: MVMCoreUIDelegateObject? @@ -398,64 +397,6 @@ import MVMCore //layoutIfNeeded() } - public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - self.delegateObject = delegateObject - FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) - - guard let dictionary = json else { return } - - groupName = dictionary.optionalStringForKey("groupName") - fieldValue = dictionary.optionalStringForKey("value") - if let fieldKey = dictionary[KeyFieldKey] as? String { - self.fieldKey = fieldKey - } - - if let isRequired = dictionary[KeyRequired] as? Bool { - self.isRequired = isRequired - } - - if let borderColorHex = dictionary["borderColor"] as? String { - layer.borderColor = UIColor.mfGet(forHex: borderColorHex).cgColor - } - - if let borderWidth = dictionary["borderWidth"] as? CGFloat { - layer.borderWidth = borderWidth - } - - if let checkColorHex = dictionary["checkColor"] as? String { - checkColor = UIColor.mfGet(forHex: checkColorHex) - } - - if let isChecked = dictionary["isChecked"] as? Bool, isChecked { - checkAndBypassAnimations(selected: isChecked) - } - - if let unCheckedBackgroundColorHex = dictionary["unCheckedBackgroundColor"] as? String { - unCheckedBackgroundColor = UIColor.mfGet(forHex: unCheckedBackgroundColorHex) - } - - if let checkedBackgroundColorHex = dictionary["checkedBackgroundColor"] as? String { - checkedBackgroundColor = UIColor.mfGet(forHex: checkedBackgroundColorHex) - } - - if let isAnimated = dictionary["isAnimated"] as? Bool { - self.isAnimated = isAnimated - } - - if let isRound = dictionary["isRound"] as? Bool { - self.isRound = isRound - } - - if let enabled = dictionary["isEnabled"] as? Bool { - isEnabled = enabled - } - - if let actionMap = dictionary.optionalDictionaryForKey("action") { - actionBlock = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } - } - } - public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) @@ -465,8 +406,7 @@ import MVMCore FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) groupName = model.groupName - fieldValue = model.value - isRequired = model.required + fieldValue = model.fieldValue if let fieldKey = model.fieldKey { self.fieldKey = fieldKey @@ -509,7 +449,7 @@ extension Checkbox: FormValidationFormFieldProtocol { } public func isValidField() -> Bool { - return isRequired ? isSelected : true + return (fieldKey != nil) ? isSelected : true } public func formFieldName() -> String? { @@ -517,6 +457,6 @@ extension Checkbox: FormValidationFormFieldProtocol { } public func formFieldValue() -> Any? { - return isSelected ? fieldValue : nil + return fieldValue ?? (isSelected ? fieldValue : nil) } } diff --git a/MVMCoreUI/Atoms/Views/CheckboxModel.swift b/MVMCoreUI/Atoms/Views/CheckboxModel.swift index 706597ff..2e08c698 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxModel.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxModel.swift @@ -17,22 +17,22 @@ import Foundation public var backgroundColor: Color? public var groupName: String? - public var value: String? public var fieldKey: String? - public var required: Bool = false - public var borderColor: Color = Color(uiColor: .black) - public var borderWidth: CGFloat = 1 + public var fieldValue: JSONValue? + public var isChecked: Bool = false + public var isEnabled: Bool = true + public var isAnimated: Bool = true + public var isRound: Bool = false + public var borderWidth: CGFloat = 1 + public var borderColor: Color = Color(uiColor: .black) public var checkColor: Color = Color(uiColor: .black) public var unCheckedBackgroundColor: Color = Color(uiColor: .clear) public var checkedBackgroundColor: Color = Color(uiColor: .clear) - public var isAnimated: Bool = true - public var isRound: Bool = false - public var isEnabled: Bool = true - public var action: ActionModelProtocol? public var disabledBackgroundColor: Color = Color(uiColor: .clear) public var disabledBorderColor: Color = Color(uiColor: .mvmCoolGray3) public var disabledCheckColor: Color = Color(uiColor: .mvmCoolGray3) + public var action: ActionModelProtocol? //-------------------------------------------------- // MARK: - Keys @@ -41,21 +41,20 @@ import Foundation private enum CodingKeys: String, CodingKey { case moleculeName case groupName - case value case fieldKey - case required - case borderColor + case fieldValue + case isChecked = "checked" + case isEnabled = "enabled" + case isAnimated = "animated" + case isRound = "round" case borderWidth - case isChecked + case borderColor case checkColor case unCheckedBackgroundColor case checkedBackgroundColor case disabledBackgroundColor case disabledCheckColor case disabledBorderColor - case isAnimated - case isRound - case isEnabled case action } @@ -68,9 +67,8 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) - value = try typeContainer.decodeIfPresent(String.self, forKey: .value) + fieldValue = try typeContainer.decodeIfPresent(JSONValue.self, forKey: .fieldValue) fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) - required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) ?? false borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) ?? 1 borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) ?? Color(uiColor: .black) checkColor = try typeContainer.decodeIfPresent(Color.self, forKey: .checkColor) ?? Color(uiColor: .black) @@ -90,9 +88,8 @@ import Foundation var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(groupName, forKey: .groupName) - try container.encodeIfPresent(value, forKey: .value) + try container.encodeIfPresent(fieldValue, forKey: .fieldValue) try container.encodeIfPresent(fieldKey, forKey: .fieldKey) - try container.encodeIfPresent(required, forKey: .required) try container.encodeIfPresent(borderColor, forKey: .borderColor) try container.encode(borderWidth, forKey: .borderWidth) try container.encode(isChecked, forKey: .isChecked)