Digital ACT-191 ONEAPP-7135 story: pass dropdown options in a structure
This commit is contained in:
parent
873d4d3367
commit
23bf242cfe
@ -19,7 +19,32 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
|||||||
var errorSwitch = Toggle()
|
var errorSwitch = Toggle()
|
||||||
var tooltipTitleTextField = TextField()
|
var tooltipTitleTextField = TextField()
|
||||||
var tooltipContentTextField = TextField()
|
var tooltipContentTextField = TextField()
|
||||||
var optionsField = TextField()
|
var optionsSwitch = Toggle()
|
||||||
|
var moreOptions: [DropdownSelect.DropdownOptionModel] = [
|
||||||
|
.init(text: "Alabama"),
|
||||||
|
.init(text: "Alaska"),
|
||||||
|
.init(text: "Arizona"),
|
||||||
|
.init(text: "Arkansas"),
|
||||||
|
.init(text: "California"),
|
||||||
|
.init(text: "Colorado"),
|
||||||
|
.init(text: "Connecticut"),
|
||||||
|
.init(text: "Delaware"),
|
||||||
|
.init(text: "District of Columbia"),
|
||||||
|
.init(text: "Florida"),
|
||||||
|
.init(text: "Georgia"),
|
||||||
|
.init(text: "Hawaii"),
|
||||||
|
.init(text: "Idaho"),
|
||||||
|
.init(text: "Illinois"),
|
||||||
|
.init(text: "Indiana"),
|
||||||
|
.init(text: "Iowa")
|
||||||
|
]
|
||||||
|
|
||||||
|
var some: [DropdownSelect.DropdownOptionModel] = [
|
||||||
|
.init(text: "Alabama"),
|
||||||
|
.init(text: "Alaska"),
|
||||||
|
.init(text: "Arizona"),
|
||||||
|
.init(text: "Arkansas")
|
||||||
|
]
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@ -39,8 +64,8 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
|||||||
addFormRow(label: "Error Text", view: errorTextField)
|
addFormRow(label: "Error Text", view: errorTextField)
|
||||||
addFormRow(label: "ToolTip Title", view: tooltipTitleTextField)
|
addFormRow(label: "ToolTip Title", view: tooltipTitleTextField)
|
||||||
addFormRow(label: "ToolTip Content", view: tooltipContentTextField)
|
addFormRow(label: "ToolTip Content", view: tooltipContentTextField)
|
||||||
addFormRow(label: "Options", view: optionsField)
|
addFormRow(label: "More Options", view: optionsSwitch)
|
||||||
|
|
||||||
disabledSwitch.onChange = { [weak self] sender in
|
disabledSwitch.onChange = { [weak self] sender in
|
||||||
self?.component.isEnabled = !sender.isOn
|
self?.component.isEnabled = !sender.isOn
|
||||||
}
|
}
|
||||||
@ -48,6 +73,11 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
|||||||
requiredSwitch.onChange = { [weak self] sender in
|
requiredSwitch.onChange = { [weak self] sender in
|
||||||
self?.component.required = sender.isOn
|
self?.component.required = sender.isOn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optionsSwitch.onChange = { [weak self] sender in
|
||||||
|
guard let self else { return }
|
||||||
|
self.component.options = sender.isOn ? self.moreOptions : self.some
|
||||||
|
}
|
||||||
|
|
||||||
errorSwitch
|
errorSwitch
|
||||||
.publisher(for: .valueChanged)
|
.publisher(for: .valueChanged)
|
||||||
@ -95,13 +125,6 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
|||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
self.component.inlineLabel = sender.isOn
|
self.component.inlineLabel = sender.isOn
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
optionsField
|
|
||||||
.textPublisher
|
|
||||||
.sink { [weak self] options in
|
|
||||||
self?.component.options = options.components(separatedBy: ",")
|
|
||||||
}.store(in: &subscribers)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupModel() {
|
func setupModel() {
|
||||||
@ -109,7 +132,12 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
|||||||
component.helperText = "For example: 123 Verizon St"
|
component.helperText = "For example: 123 Verizon St"
|
||||||
component.errorText = "Enter a valid address."
|
component.errorText = "Enter a valid address."
|
||||||
component.tooltipModel = .init(title: "Check the formatting of your address", content:"House/Building number then street name")
|
component.tooltipModel = .init(title: "Check the formatting of your address", content:"House/Building number then street name")
|
||||||
component.options = ["One", "Two", "Three"]
|
component.options = moreOptions
|
||||||
|
|
||||||
|
/// callback to know which option chose
|
||||||
|
component.onDropdownItemSelect = { option in
|
||||||
|
print("selected option text: \(option.text)")
|
||||||
|
}
|
||||||
|
|
||||||
//setup UI
|
//setup UI
|
||||||
disabledSwitch.isOn = !component.isEnabled
|
disabledSwitch.isOn = !component.isEnabled
|
||||||
@ -121,7 +149,7 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
|||||||
errorTextField.text = component.errorText
|
errorTextField.text = component.errorText
|
||||||
tooltipTitleTextField.text = component.tooltipModel?.title
|
tooltipTitleTextField.text = component.tooltipModel?.title
|
||||||
tooltipContentTextField.text = component.tooltipModel?.content
|
tooltipContentTextField.text = component.tooltipModel?.content
|
||||||
optionsField.text = "One,Two,Three"
|
optionsSwitch.isOn = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupPicker() {
|
func setupPicker() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user