refactored checkbox action to didSet
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
5a47b32789
commit
ac23b0dc41
@ -24,17 +24,13 @@ import VDS
|
||||
var fieldKey: String?
|
||||
var fieldValue: JSONValue?
|
||||
var groupName: String?
|
||||
|
||||
/// Disables all selection logic when setting the value of isSelected, reducing it to a stored property.
|
||||
open var updateSelectionOnly: Bool = false
|
||||
|
||||
|
||||
/// Action Block called when the switch is selected.
|
||||
open var actionBlock: ActionBlock? {
|
||||
get { nil }
|
||||
set {
|
||||
if let action = newValue {
|
||||
didSet {
|
||||
if let actionBlock {
|
||||
onChange = { _ in
|
||||
action()
|
||||
actionBlock()
|
||||
}
|
||||
} else {
|
||||
onChange = nil
|
||||
@ -42,20 +38,6 @@ import VDS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
The represented state of the Checkbox.
|
||||
|
||||
Setting updateSelectionOnly to true bypasses the animation logic inherent with setting this property.
|
||||
*/
|
||||
override open var isSelected: Bool {
|
||||
didSet {
|
||||
if !updateSelectionOnly {
|
||||
viewModel.selected = isSelected
|
||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
@ -92,6 +74,12 @@ import VDS
|
||||
open func toggleAndAction() {
|
||||
toggle()
|
||||
}
|
||||
|
||||
open override func toggle() {
|
||||
super.toggle()
|
||||
viewModel.selected = isSelected
|
||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Methods
|
||||
@ -144,11 +132,7 @@ import VDS
|
||||
//properties
|
||||
isEnabled = viewModel.enabled && !viewModel.readOnly
|
||||
isAnimated = viewModel.animated
|
||||
if viewModel.selected {
|
||||
updateSelectionOnly = true
|
||||
isSelected = viewModel.selected
|
||||
updateSelectionOnly = false
|
||||
}
|
||||
isSelected = viewModel.selected
|
||||
|
||||
//events
|
||||
viewModel.updateUI = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user