From 646dfd6a10df871831ad0dfe2f20255bfda3c544 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 7 Apr 2020 15:49:58 -0400 Subject: [PATCH] selction fixes and reuse fixes --- MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift | 9 +++++++++ MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonModel.swift | 4 +--- .../Atoms/Buttons/RadioButtonSelectionHelper.swift | 9 ++++++--- MVMCoreUI/FormUIHelpers/FormValidator.swift | 3 ++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift index 98532549..3d52e63b 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift @@ -19,6 +19,12 @@ import UIKit } } + public override var isSelected: Bool { + didSet { + radioModel?.state = isSelected + } + } + public var enabledColor: UIColor = .black public var disabledColor: UIColor = .mfSilver() public var delegateObject: MVMCoreUIDelegateObject? @@ -128,6 +134,9 @@ import UIKit self.delegateObject = delegateObject isSelected = model.state + if model.state { + print("log") + } RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject) } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonModel.swift index 579c0ed9..99e15280 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonModel.swift @@ -47,7 +47,6 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { public init(_ state: Bool) { self.state = state - baseValue = state } //-------------------------------------------------- @@ -55,7 +54,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { //-------------------------------------------------- public func formFieldValue() -> AnyHashable? { - return state + return fieldValue } //-------------------------------------------------- @@ -75,7 +74,6 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - baseValue = state fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) { self.groupName = groupName diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift index 3decadb5..dbc3f7fe 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift @@ -16,8 +16,11 @@ import UIKit private var fieldGroupName: String? public var baseValue: AnyHashable? - init(_ fieldKey: String?) { - self.fieldKey = fieldKey + init(_ radioButtonModel: RadioButtonModel?) { + self.fieldKey = radioButtonModel?.fieldKey + if radioButtonModel?.state ?? false { + self.baseValue = radioButtonModel?.formFieldValue() + } } public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton, delegateObject: MVMCoreUIDelegateObject?) { @@ -26,7 +29,7 @@ import UIKit return } - let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel.fieldKey) + let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel) radioButtonSelectionHelper.fieldGroupName = radioButtonModel.fieldKey formValidator.radioButtonsModelByGroup[groupName] = radioButtonSelectionHelper diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index 592132f5..661036d8 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -66,7 +66,8 @@ import MVMCore return valid } for group in formRules { - valid = valid && validateGroup(group) + let groupValid = validateGroup(group) + valid = valid && groupValid } return valid }