multi select

This commit is contained in:
Kevin G Christiano 2021-02-15 14:07:50 -05:00
parent cb981e29a9
commit a56fd32b16
3 changed files with 12 additions and 6 deletions

View File

@ -85,6 +85,7 @@ open class ItemDropdownEntryField: BaseItemPickerEntryField {
pickerData = model.options
if let pickerView = pickerView, let index = model.selectedIndex {
self.pickerView?.selectRow(index, inComponent: 0, animated: false)
self.pickerView(pickerView, didSelectRow: index, inComponent: 0)
}
}

View File

@ -106,6 +106,7 @@ open class MultiItemDropdownEntryField: BaseItemPickerEntryField {
if let pickerView = pickerView {
// Select initial rows if selectedIndexes retains value.
for (component, row) in model.selectedIndexes {
self.pickerView?.selectRow(row, inComponent: component, animated: false)
self.pickerView(pickerView, didSelectRow: row, inComponent: component)
}
}
@ -133,12 +134,13 @@ open class MultiItemDropdownEntryField: BaseItemPickerEntryField {
@objc public func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
guard !pickerComponents.isEmpty,
!pickerComponents[component].isEmpty,
let rowText = dropdownModel?.selectedRowText
!pickerComponents[component].isEmpty
else { return }
observeDropdownChange?(text ?? "", rowText)
text = rowText
let oldText = text ?? ""
dropdownModel?.selectedIndexes[component] = row
let newText = dropdownModel?.selectedRowText
observeDropdownChange?(oldText, newText ?? "")
text = newText
}
}

View File

@ -35,8 +35,8 @@
public var keyboardOverride: String?
public var type: EntryType?
public var clearTextOnTap: Bool = false
public var displayFormat: String? = "(?=\\d{5})\\d"
public var displayMask: String? = ""
public var displayFormat: String?
public var displayMask: String?
//--------------------------------------------------
// MARK: - Methods
@ -103,6 +103,7 @@
case type
case clearTextOnTap
case displayFormat
case displayMask
}
//--------------------------------------------------
@ -116,6 +117,7 @@
placeholder = try typeContainer.decodeIfPresent(String.self, forKey: .placeholder)
displayFormat = try typeContainer.decodeIfPresent(String.self, forKey: .displayFormat)
keyboardOverride = try typeContainer.decodeIfPresent(String.self, forKey: .keyboardOverride)
displayMask = try typeContainer.decodeIfPresent(String.self, forKey: .displayMask)
type = try typeContainer.decodeIfPresent(EntryType.self, forKey: .type)
if let clearTextOnTap = try typeContainer.decodeIfPresent(Bool.self, forKey: .clearTextOnTap) {
@ -143,6 +145,7 @@
try container.encodeIfPresent(type, forKey: .type)
try container.encodeIfPresent(displayFormat, forKey: .displayFormat)
try container.encodeIfPresent(keyboardOverride, forKey: .keyboardOverride)
try container.encodeIfPresent(displayMask, forKey: .displayMask)
try container.encode(enabledTextColor, forKey: .enabledTextColor)
try container.encode(disabledTextColor, forKey: .disabledTextColor)
try container.encode(clearTextOnTap, forKey: .clearTextOnTap)