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 tooltipTitleTextField = 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() {
|
||||
super.viewDidLoad()
|
||||
@ -39,7 +64,7 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
||||
addFormRow(label: "Error Text", view: errorTextField)
|
||||
addFormRow(label: "ToolTip Title", view: tooltipTitleTextField)
|
||||
addFormRow(label: "ToolTip Content", view: tooltipContentTextField)
|
||||
addFormRow(label: "Options", view: optionsField)
|
||||
addFormRow(label: "More Options", view: optionsSwitch)
|
||||
|
||||
disabledSwitch.onChange = { [weak self] sender in
|
||||
self?.component.isEnabled = !sender.isOn
|
||||
@ -49,6 +74,11 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
||||
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
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { [weak self] sender in
|
||||
@ -95,13 +125,6 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
||||
guard let self else { return }
|
||||
self.component.inlineLabel = sender.isOn
|
||||
}.store(in: &subscribers)
|
||||
|
||||
optionsField
|
||||
.textPublisher
|
||||
.sink { [weak self] options in
|
||||
self?.component.options = options.components(separatedBy: ",")
|
||||
}.store(in: &subscribers)
|
||||
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
@ -109,7 +132,12 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
||||
component.helperText = "For example: 123 Verizon St"
|
||||
component.errorText = "Enter a valid address."
|
||||
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
|
||||
disabledSwitch.isOn = !component.isEnabled
|
||||
@ -121,7 +149,7 @@ class DropdownSelectViewController: BaseViewController<DropdownSelect> {
|
||||
errorTextField.text = component.errorText
|
||||
tooltipTitleTextField.text = component.tooltipModel?.title
|
||||
tooltipContentTextField.text = component.tooltipModel?.content
|
||||
optionsField.text = "One,Two,Three"
|
||||
optionsSwitch.isOn = true
|
||||
}
|
||||
|
||||
func setupPicker() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user