organized radio

This commit is contained in:
Kevin G Christiano 2020-04-07 14:33:57 -04:00
parent 752ff76e79
commit 8072d8d4aa
2 changed files with 33 additions and 18 deletions

View File

@ -8,6 +8,7 @@
import UIKit
@objcMembers open class RadioButton: Control {
//--------------------------------------------------
// MARK: - Properties
@ -19,8 +20,8 @@ import UIKit
}
}
public var enabledColor: UIColor = .black
public var disabledColor: UIColor = .mfSilver()
public var enabledColor: UIColor = .mvmBlack
public var disabledColor: UIColor = .mvmCoolGray6
public var delegateObject: MVMCoreUIDelegateObject?
public var radioModel: RadioButtonModel? {
@ -108,7 +109,7 @@ import UIKit
open override func setupView() {
super.setupView()
backgroundColor = .white
backgroundColor = .mvmWhite
clipsToBounds = true
widthConstraint = widthAnchor.constraint(equalToConstant: 30)
widthConstraint?.isActive = true

View File

@ -7,24 +7,36 @@
//
import Foundation
import UIKit
@objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public var fieldKey: String?
public var groupName: String = FormValidator.defaultGroupName
private var selectedRadioButton: RadioButton?
private var fieldGroupName: String?
public var baseValue: AnyHashable?
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
init(_ fieldKey: String?) {
self.fieldKey = fieldKey
}
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton, delegateObject: MVMCoreUIDelegateObject?) {
guard let groupName = radioButtonModel.fieldKey,
let formValidator = delegateObject?.formHolderDelegate?.formValidator else {
return
}
let formValidator = delegateObject?.formHolderDelegate?.formValidator
else { return }
let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel.fieldKey)
radioButtonSelectionHelper.fieldGroupName = radioButtonModel.fieldKey
@ -37,6 +49,7 @@ import UIKit
}
public func selected(_ radioButton: RadioButton) {
selectedRadioButton?.isSelected = false
selectedRadioButton = radioButton
selectedRadioButton?.isSelected = true
@ -45,8 +58,9 @@ import UIKit
// MARK: - FormValidationFormFieldProtocol
extension RadioButtonSelectionHelper {
public func formFieldGroupName() -> String? {
return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName
return selectedRadioButton?.formFieldGroupName() ?? fieldGroupName
}
public func formFieldValue() -> AnyHashable? {