organized radio
This commit is contained in:
parent
752ff76e79
commit
8072d8d4aa
@ -8,6 +8,7 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
@objcMembers open class RadioButton: Control {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
@ -18,19 +19,19 @@ import UIKit
|
||||
widthConstraint?.constant = diameter
|
||||
}
|
||||
}
|
||||
|
||||
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? {
|
||||
return model as? RadioButtonModel
|
||||
}
|
||||
|
||||
|
||||
lazy public var radioGroupName: String? = {
|
||||
return radioModel?.fieldKey
|
||||
}()
|
||||
|
||||
|
||||
lazy public var radioButtonSelectionHelper: RadioButtonSelectionHelper? = {
|
||||
if let radioGroupName = radioGroupName,
|
||||
let radioButtonModel = delegateObject?.formHolderDelegate?.formValidator?.radioButtonsModelByGroup[radioGroupName] {
|
||||
@ -100,7 +101,7 @@ import UIKit
|
||||
public func formFieldValue() -> AnyHashable? {
|
||||
return radioModel?.fieldValue
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - MVMViewProtocol
|
||||
//--------------------------------------------------
|
||||
@ -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
|
||||
@ -120,7 +121,7 @@ import UIKit
|
||||
accessibilityTraits = .button
|
||||
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint")
|
||||
}
|
||||
|
||||
|
||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
|
||||
@ -130,9 +131,9 @@ import UIKit
|
||||
isSelected = model.state
|
||||
RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject)
|
||||
}
|
||||
|
||||
|
||||
public override func reset() {
|
||||
super.reset()
|
||||
backgroundColor = .white
|
||||
super.reset()
|
||||
backgroundColor = .white
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,29 +7,41 @@
|
||||
//
|
||||
|
||||
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
|
||||
formValidator.radioButtonsModelByGroup[groupName] = radioButtonSelectionHelper
|
||||
|
||||
|
||||
if radioButtonModel.state {
|
||||
radioButtonSelectionHelper.selectedRadioButton = radioButton
|
||||
}
|
||||
@ -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? {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user