selction fixes and reuse fixes

This commit is contained in:
Suresh, Kamlesh 2020-04-07 15:49:58 -04:00
parent 1d6ed35d84
commit 646dfd6a10
4 changed files with 18 additions and 7 deletions

View File

@ -19,6 +19,12 @@ import UIKit
} }
} }
public override var isSelected: Bool {
didSet {
radioModel?.state = isSelected
}
}
public var enabledColor: UIColor = .black public var enabledColor: UIColor = .black
public var disabledColor: UIColor = .mfSilver() public var disabledColor: UIColor = .mfSilver()
public var delegateObject: MVMCoreUIDelegateObject? public var delegateObject: MVMCoreUIDelegateObject?
@ -128,6 +134,9 @@ import UIKit
self.delegateObject = delegateObject self.delegateObject = delegateObject
isSelected = model.state isSelected = model.state
if model.state {
print("log")
}
RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject) RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject)
} }

View File

@ -47,7 +47,6 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
public init(_ state: Bool) { public init(_ state: Bool) {
self.state = state self.state = state
baseValue = state
} }
//-------------------------------------------------- //--------------------------------------------------
@ -55,7 +54,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
//-------------------------------------------------- //--------------------------------------------------
public func formFieldValue() -> AnyHashable? { 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) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
baseValue = state
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) { if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
self.groupName = groupName self.groupName = groupName

View File

@ -16,8 +16,11 @@ import UIKit
private var fieldGroupName: String? private var fieldGroupName: String?
public var baseValue: AnyHashable? public var baseValue: AnyHashable?
init(_ fieldKey: String?) { init(_ radioButtonModel: RadioButtonModel?) {
self.fieldKey = fieldKey self.fieldKey = radioButtonModel?.fieldKey
if radioButtonModel?.state ?? false {
self.baseValue = radioButtonModel?.formFieldValue()
}
} }
public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton, delegateObject: MVMCoreUIDelegateObject?) { public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton, delegateObject: MVMCoreUIDelegateObject?) {
@ -26,7 +29,7 @@ import UIKit
return return
} }
let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel.fieldKey) let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel)
radioButtonSelectionHelper.fieldGroupName = radioButtonModel.fieldKey radioButtonSelectionHelper.fieldGroupName = radioButtonModel.fieldKey
formValidator.radioButtonsModelByGroup[groupName] = radioButtonSelectionHelper formValidator.radioButtonsModelByGroup[groupName] = radioButtonSelectionHelper

View File

@ -66,7 +66,8 @@ import MVMCore
return valid return valid
} }
for group in formRules { for group in formRules {
valid = valid && validateGroup(group) let groupValid = validateGroup(group)
valid = valid && groupValid
} }
return valid return valid
} }