fixes
This commit is contained in:
parent
0f1ea89623
commit
6b71115eb0
@ -16,12 +16,16 @@ import UIKit
|
|||||||
var dummyButton: MFCustomButton?
|
var dummyButton: MFCustomButton?
|
||||||
let label = Label()
|
let label = Label()
|
||||||
|
|
||||||
var groupName: String?
|
|
||||||
var fieldKey: String?
|
var fieldKey: String?
|
||||||
var formValue: Bool?
|
var formValue: Bool?
|
||||||
var isRequired: Bool = false
|
var isRequired: Bool = false
|
||||||
var radioButtonModel: RadioButtonModel?
|
var radioButtonModel: RadioButtonModel?
|
||||||
|
|
||||||
|
lazy var groupName: String? = {
|
||||||
|
[unowned self] in
|
||||||
|
return json?.optionalStringForKey("groupName") ?? json?.optionalStringForKey("fieldKey")
|
||||||
|
}()
|
||||||
|
|
||||||
// MARK: - Inits
|
// MARK: - Inits
|
||||||
public init() {
|
public init() {
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
@ -115,22 +119,15 @@ extension RadioButton {
|
|||||||
guard let jsonDictionary = json else {
|
guard let jsonDictionary = json else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
groupName = jsonDictionary.optionalStringForKey("groupName")
|
|
||||||
fieldKey = jsonDictionary.optionalStringForKey("fieldKey")
|
fieldKey = jsonDictionary.optionalStringForKey("fieldKey")
|
||||||
isRequired = jsonDictionary.boolForKey("required")
|
isRequired = jsonDictionary.boolForKey("required")
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
|
||||||
radioButtonModel = RadioButtonModel.setupForRadioButtonGroup(radioButton: self,
|
let radioButtonModel = RadioButtonModel.setupForRadioButtonGroup(radioButton: self,
|
||||||
formValidator: delegateObject?.formValidationProtocol?.formValidatorModel?())
|
formValidator: delegateObject?.formValidationProtocol?.formValidatorModel?())
|
||||||
|
FormValidator.setupValidation(molecule: radioButtonModel, delegate: delegateObject?.formValidationProtocol)
|
||||||
/* If the radio button has a group, it will have RadioButtonModel.
|
self.radioButtonModel = 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
label.setWithJSON(jsonDictionary.optionalDictionaryForKey(KeyLabel),
|
label.setWithJSON(jsonDictionary.optionalDictionaryForKey(KeyLabel),
|
||||||
delegateObject: delegateObject,
|
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
|
// MARK: Accessibility
|
||||||
extension RadioButton {
|
extension RadioButton {
|
||||||
func changeAccessibilityLabel() {
|
func changeAccessibilityLabel() {
|
||||||
|
|||||||
@ -13,10 +13,10 @@ import UIKit
|
|||||||
|
|
||||||
private var selectedRadioButton: RadioButton?
|
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,
|
guard let groupName = radioButton.groupName,
|
||||||
let formValidator = formValidator else {
|
let formValidator = formValidator else {
|
||||||
return nil
|
return RadioButtonModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
let radioButtonModel = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonModel()
|
let radioButtonModel = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonModel()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user