organized radio
This commit is contained in:
parent
752ff76e79
commit
8072d8d4aa
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|
||||||
@objcMembers open class RadioButton: Control {
|
@objcMembers open class RadioButton: Control {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
@ -19,8 +20,8 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var enabledColor: UIColor = .black
|
public var enabledColor: UIColor = .mvmBlack
|
||||||
public var disabledColor: UIColor = .mfSilver()
|
public var disabledColor: UIColor = .mvmCoolGray6
|
||||||
public var delegateObject: MVMCoreUIDelegateObject?
|
public var delegateObject: MVMCoreUIDelegateObject?
|
||||||
|
|
||||||
public var radioModel: RadioButtonModel? {
|
public var radioModel: RadioButtonModel? {
|
||||||
@ -108,7 +109,7 @@ import UIKit
|
|||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|
||||||
backgroundColor = .white
|
backgroundColor = .mvmWhite
|
||||||
clipsToBounds = true
|
clipsToBounds = true
|
||||||
widthConstraint = widthAnchor.constraint(equalToConstant: 30)
|
widthConstraint = widthAnchor.constraint(equalToConstant: 30)
|
||||||
widthConstraint?.isActive = true
|
widthConstraint?.isActive = true
|
||||||
@ -132,7 +133,7 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override func reset() {
|
public override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
backgroundColor = .white
|
backgroundColor = .white
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,24 +7,36 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
|
||||||
|
|
||||||
@objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol {
|
@objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public var fieldKey: String?
|
public var fieldKey: String?
|
||||||
public var groupName: String = FormValidator.defaultGroupName
|
public var groupName: String = FormValidator.defaultGroupName
|
||||||
private var selectedRadioButton: RadioButton?
|
private var selectedRadioButton: RadioButton?
|
||||||
private var fieldGroupName: String?
|
private var fieldGroupName: String?
|
||||||
public var baseValue: AnyHashable?
|
public var baseValue: AnyHashable?
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Initializer
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
init(_ fieldKey: String?) {
|
init(_ fieldKey: String?) {
|
||||||
self.fieldKey = fieldKey
|
self.fieldKey = fieldKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Methods
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton, delegateObject: MVMCoreUIDelegateObject?) {
|
public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton, delegateObject: MVMCoreUIDelegateObject?) {
|
||||||
|
|
||||||
guard let groupName = radioButtonModel.fieldKey,
|
guard let groupName = radioButtonModel.fieldKey,
|
||||||
let formValidator = delegateObject?.formHolderDelegate?.formValidator else {
|
let formValidator = delegateObject?.formHolderDelegate?.formValidator
|
||||||
return
|
else { return }
|
||||||
}
|
|
||||||
|
|
||||||
let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel.fieldKey)
|
let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel.fieldKey)
|
||||||
radioButtonSelectionHelper.fieldGroupName = radioButtonModel.fieldKey
|
radioButtonSelectionHelper.fieldGroupName = radioButtonModel.fieldKey
|
||||||
@ -37,6 +49,7 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func selected(_ radioButton: RadioButton) {
|
public func selected(_ radioButton: RadioButton) {
|
||||||
|
|
||||||
selectedRadioButton?.isSelected = false
|
selectedRadioButton?.isSelected = false
|
||||||
selectedRadioButton = radioButton
|
selectedRadioButton = radioButton
|
||||||
selectedRadioButton?.isSelected = true
|
selectedRadioButton?.isSelected = true
|
||||||
@ -45,8 +58,9 @@ import UIKit
|
|||||||
|
|
||||||
// MARK: - FormValidationFormFieldProtocol
|
// MARK: - FormValidationFormFieldProtocol
|
||||||
extension RadioButtonSelectionHelper {
|
extension RadioButtonSelectionHelper {
|
||||||
|
|
||||||
public func formFieldGroupName() -> String? {
|
public func formFieldGroupName() -> String? {
|
||||||
return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName
|
return selectedRadioButton?.formFieldGroupName() ?? fieldGroupName
|
||||||
}
|
}
|
||||||
|
|
||||||
public func formFieldValue() -> AnyHashable? {
|
public func formFieldValue() -> AnyHashable? {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user