3

This is a question about the library, Eureka.

I have a PushRow with a number of options(names). And I also set the first item of those options as the one selected by default upon initialization.

var names = ["Jake", "Cassie", "Rachel", "Marco", "Ax", "Tobias"]

<<< PushRow<WindowStyle>("NamesRow") {
        $0.title = "Names"
        $0.options = names
        $0.value = names.first
    }

I run the app and Jake is selected by default as expected. If I tap on the PushRow and reselect Jake and now it gets deselected. This is expected behavior, I assume. But I want to avoid deselection if I tap on an already selected option row.

The row property in onChange callback closure returns nil if the same option gets selected. I tried to do a nil check and exit early but it doesn't work. It seems onChange method is fired after all that deselection happens.

.onChange { row in
    guard let selectedName = row.value else {
        return
    }
}

How can I disable deselection?

Isuru
  • 30,617
  • 60
  • 187
  • 303

2 Answers2

5

Not sure if you've found an answer for this.

And, although I haven't done this myself, I'd like to point in the right direction.

They have included it in their update to Swift 3.

Please find the same at, https://github.com/xmartlabs/Eureka/issues/261#issuecomment-255439929

And just for reference,

.onPresent { form, selectorController in
         selectorController.enableDeselection = false
}
Shyam
  • 561
  • 5
  • 22
1

The question is a bit older, but if someone is still looking for the answer:
You can do this with:

}.onPresent { form, row in
                row.enableDeselection = false}