xmartlabs / Eureka

Elegant iOS form builder in Swift
https://eurekacommunity.github.io
MIT License
11.78k stars 1.33k forks source link

ChecklistRow, initial value #2115

Closed ebeland closed 3 years ago

ebeland commented 3 years ago

Before submitting issues ...

When submitting issues, please provide the following information to help maintainers to fix the problem faster:

ebeland commented 3 years ago

I'm trying to set the initial value of a Selectable Section and cannot find the right way to do so.

form +++ SelectableSection<ListCheckRow<AlbumSortType>>("Sort By", selectionType: .singleSelection(enableDeselection: false))

    form.last!.header = HeaderFooterView<UIView>(HeaderFooterProvider.class)
    form.last!.header?.height = { 0.1 }

      for option in self.sortOptions {
            let optionString = option.titleText() + option.secondarySortingText(isAscending: option.isAscending)
            self.form.last! <<< ListCheckRow<AlbumSortType>(optionString) { listRow in
                listRow.title = optionString
                listRow.selectableValue = option
                listRow.value = nil
                if option == self.selectedAlbumSortType {
                    // I tried selecting here it doesn't set the value.
                }
            }
            .onChange({ row in
                self.selectedAlbumSortType = row.selectableValue
            })
        }

I've tried setting it a number of ways and can't find a definitive answer in the docs / Github / Stack. Any clues would be appreciated.

Selecting rows that match my current value has not worked so far.

I also tried variations on this.

form.setValues(["Sort By": [self.selectedAlbumSortType]])

mats-claassen commented 3 years ago

If listRow.value == listRow.selectableValue (so, when it is not nil) then it is selected. What you can do is:

listRow.value = option == self.selectedAlbumSortType ? option : nil
ebeland commented 3 years ago

Thank you that worked. Never would have guessed that.