some checks for analytics change

This commit is contained in:
Kevin G Christiano 2020-09-18 13:08:08 -04:00
parent 44dad67961
commit 68274505fb
2 changed files with 20 additions and 8 deletions

View File

@ -32,6 +32,8 @@ open class ItemDropdownEntryField: BaseDropdownEntryField {
return model as? ItemDropdownEntryFieldModel
}
private var systemWillSetItem = false
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
@ -109,8 +111,10 @@ open class ItemDropdownEntryField: BaseDropdownEntryField {
pickerData = model.options
setPickerDelegates(delegate: self)
if let pickerView = pickerView {
self.pickerView(pickerView, didSelectRow: model.selectedIndex, inComponent: 0)
if let pickerView = pickerView, let index = model.selectedIndex {
systemWillSetItem = true
self.pickerView(pickerView, didSelectRow: index, inComponent: 0)
systemWillSetItem = false
}
}
}
@ -138,7 +142,9 @@ extension ItemDropdownEntryField: UIPickerViewDelegate, UIPickerViewDataSource {
observeDropdownChange?(text ?? "", pickerData[row])
text = pickerData[row]
itemDropdownEntryFieldModel?.selectedIndex = row
performDropdownAction()
if !systemWillSetItem {
performDropdownAction()
}
}
}

View File

@ -16,11 +16,14 @@
}
public var options: [String] = []
public var selectedIndex: Int = 0
public var selectedIndex: Int?
public override func formFieldValue() -> AnyHashable? {
guard !options.isEmpty else { return nil }
return options[selectedIndex]
guard !options.isEmpty,
let index = selectedIndex
else { return nil }
return options[index]
}
//--------------------------------------------------
@ -45,13 +48,16 @@
if let selectedIndex = try typeContainer.decodeIfPresent(Int.self, forKey: .selectedIndex) {
self.selectedIndex = selectedIndex
}
baseValue = options.indices.contains(selectedIndex) ? options[selectedIndex] : nil
if let index = selectedIndex {
baseValue = options.indices.contains(index) ? options[index] : nil
}
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(options, forKey: .options)
try container.encode(options, forKey: .selectedIndex)
try container.encodeIfPresent(options, forKey: .selectedIndex)
}
}