fixes
This commit is contained in:
parent
0f1ea89623
commit
6b71115eb0
@ -16,12 +16,16 @@ import UIKit
|
||||
var dummyButton: MFCustomButton?
|
||||
let label = Label()
|
||||
|
||||
var groupName: String?
|
||||
var fieldKey: String?
|
||||
var formValue: Bool?
|
||||
var isRequired: Bool = false
|
||||
var radioButtonModel: RadioButtonModel?
|
||||
|
||||
lazy var groupName: String? = {
|
||||
[unowned self] in
|
||||
return json?.optionalStringForKey("groupName") ?? json?.optionalStringForKey("fieldKey")
|
||||
}()
|
||||
|
||||
// MARK: - Inits
|
||||
public init() {
|
||||
super.init(frame: .zero)
|
||||
@ -115,22 +119,15 @@ extension RadioButton {
|
||||
guard let jsonDictionary = json else {
|
||||
return
|
||||
}
|
||||
groupName = jsonDictionary.optionalStringForKey("groupName")
|
||||
|
||||
fieldKey = jsonDictionary.optionalStringForKey("fieldKey")
|
||||
isRequired = jsonDictionary.boolForKey("required")
|
||||
self.delegateObject = delegateObject
|
||||
|
||||
radioButtonModel = RadioButtonModel.setupForRadioButtonGroup(radioButton: self,
|
||||
let radioButtonModel = RadioButtonModel.setupForRadioButtonGroup(radioButton: self,
|
||||
formValidator: delegateObject?.formValidationProtocol?.formValidatorModel?())
|
||||
|
||||
/* If the radio button has a group, it will have RadioButtonModel.
|
||||
In this case the RadioButtonModel should be the validator
|
||||
*/
|
||||
if let radioButtonModel = radioButtonModel {
|
||||
FormValidator.setupValidation(molecule: radioButtonModel, delegate: delegateObject?.formValidationProtocol)
|
||||
} else {
|
||||
FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol)
|
||||
}
|
||||
FormValidator.setupValidation(molecule: radioButtonModel, delegate: delegateObject?.formValidationProtocol)
|
||||
self.radioButtonModel = radioButtonModel
|
||||
|
||||
label.setWithJSON(jsonDictionary.optionalDictionaryForKey(KeyLabel),
|
||||
delegateObject: delegateObject,
|
||||
@ -139,28 +136,6 @@ extension RadioButton {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - FormValidationProtocol
|
||||
extension RadioButton: FormValidationProtocol {
|
||||
// Used to check the validity of the field, to enable/disable the primary button.
|
||||
@objc public func isValidField() -> Bool {
|
||||
guard isRequired else {
|
||||
return true
|
||||
}
|
||||
return radioButtonModel?.isValidField() ?? false
|
||||
}
|
||||
|
||||
// The Field name key value pair for sending to server
|
||||
@objc public func formFieldName() -> String? {
|
||||
return radioButtonModel?.formFieldName() ?? json?.optionalStringForKey("fieldKey")
|
||||
}
|
||||
|
||||
// The Field value key value pair for sending to server
|
||||
@objc public func formFieldValue() -> Any? {
|
||||
return radioButtonModel?.formFieldValue() ?? radioButton.isSelected
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Accessibility
|
||||
extension RadioButton {
|
||||
func changeAccessibilityLabel() {
|
||||
|
||||
@ -13,10 +13,10 @@ import UIKit
|
||||
|
||||
private var selectedRadioButton: RadioButton?
|
||||
|
||||
public static func setupForRadioButtonGroup(radioButton: RadioButton, formValidator: FormValidator?) -> RadioButtonModel? {
|
||||
public static func setupForRadioButtonGroup(radioButton: RadioButton, formValidator: FormValidator?) -> RadioButtonModel {
|
||||
guard let groupName = radioButton.groupName,
|
||||
let formValidator = formValidator else {
|
||||
return nil
|
||||
return RadioButtonModel()
|
||||
}
|
||||
|
||||
let radioButtonModel = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonModel()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user