diff --git a/MVMCoreUI/Molecules/RadioButton.swift b/MVMCoreUI/Molecules/RadioButton.swift index 57115d68..059bc5b6 100644 --- a/MVMCoreUI/Molecules/RadioButton.swift +++ b/MVMCoreUI/Molecules/RadioButton.swift @@ -16,12 +16,21 @@ import UIKit var fieldKey: String? var formValue: Bool? var isRequired: Bool = false - var radioButtonModel: RadioButtonModel? - + lazy var radioGroupName: String? = { [unowned self] in return json?.optionalStringForKey("radioGroupName") ?? json?.optionalStringForKey("fieldKey") }() + + lazy var radioButtonModel: RadioButtonModel? = { + [unowned self] in + if let radioGroupName = radioGroupName, + let radioButtonModel = delegateObject?.formValidationProtocol?.formValidatorModel?()?.radioButtonsModelByGroup[radioGroupName] { + return radioButtonModel + } else { + return nil + } + }() // MARK: - Inits public init() { @@ -101,6 +110,5 @@ extension RadioButton { let radioButtonModel = RadioButtonModel.setupForRadioButtonGroup(radioButton: self, formValidator: delegateObject?.formValidationProtocol?.formValidatorModel?()) FormValidator.setupValidation(molecule: radioButtonModel, delegate: delegateObject?.formValidationProtocol) - self.radioButtonModel = radioButtonModel } } diff --git a/MVMCoreUI/Molecules/RadioButtonModel.swift b/MVMCoreUI/Molecules/RadioButtonModel.swift index 68e95790..a72bd889 100644 --- a/MVMCoreUI/Molecules/RadioButtonModel.swift +++ b/MVMCoreUI/Molecules/RadioButtonModel.swift @@ -49,6 +49,6 @@ extension RadioButtonModel: FormValidationFormFieldProtocol { } // The field value key value pair for sending to server @objc public func formFieldValue() -> Any? { - return selectedRadioButton != nil ? true : false + return selectedRadioButton != nil ? true : false } }