key update

This commit is contained in:
Pfeil, Scott Robert 2020-03-06 14:20:58 -05:00
parent b54694690e
commit 4ae6a393d3
2 changed files with 20 additions and 83 deletions

View File

@ -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)
}
}

View File

@ -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)