Eureka: PushRow - Prevent Nil

Created on 12 Feb 2016  路  12Comments  路  Source: xmartlabs/Eureka

This may be a basic question - but for a PushRow - is there a way to make it to where if I select the same row twice, it doesn't "unselect" the row?

Basically I don't want them to be able to unselect values from PushRows... more similar to how iOS does it on forms such as "New Event" on Calendar.

PushRow SelectableSection swift 3.0 feature request

Most helpful comment

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

do the trick

All 12 comments

Currently the PushRow is using SelectorViewController which uses a SelectableSection which supports enabling or disabling this feature. But there is no way to change the default for now. We might add it in the future.

+1
By default PushRow should not allow nil selection. Single selection usually means exactly one option needs to be selected.

Merged to Swift3 branch in #551. Will be supported as soon as Swift 3 becomes official

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

do the trick

For Swift 2.2, you can achieve the same affect by using:

.onChange({ row in
    if row.value == nil {
        row.value = // set to previously used value or default
        row.reload()
    }
})

Thanks @Laptopmini, you're missing a ) at the end there though 馃

Fixed. Good catch @andrewprocter

@mtnbarreto , Is there a similar implementation for MultipleSelectorRow, like you've mentioned earlier in https://github.com/xmartlabs/Eureka/issues/261#issuecomment-255439929 ?

I'd want to make sure that at least one is selected or having a default 'None' or 'Never' option if deselection is allowed?

@mats-claassen and @mtnbarreto , I've noticed in Eureka/Source/Core/SelectableSection.swift, the below code.

public enum SelectionType {

    /**
     * Multiple options can be selected at once
     */
    case multipleSelection

    /**
     * Only one selection at a time. Can additionally specify if deselection is enabled or not.
     */
    case singleSelection(enableDeselection: Bool)
}

Which means, enableDeselection hasn't been implemented yet for multipleSelection!! Is there any chance that it would be?

Thank you both, for the amazing work on Eureka.

@mohan-shyam
I think normally in a multiple selection you should allow to deselect all options. You can later validate that at least one is selected and point the user to that row if he did not select any option.

@mtnbarreto
this snippet certainly avoids to deselect the value but also causes the presented controller to don't dismiss on selection anymore which in my case leaves the user trapped on that view. Am I missing something else?

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

@mats-claassen @mtnbarreto can you consider as a possible solution for what @jaimeagudo stated and the use case described in #551 to add a flag enabledReselection to singleSelection SelectionType or just revert the change?
We also faced a bug in our project after updating to 2.0 that was caused by onSelectSelectableRow not being called when selecting already selected row. When this happens we need to push another view controller.
To solve that and to avoid subclassing sections (we already subclass SelectorViewController) we have to enable deselection and reset value to initial in case of nil when receiving callback. But we have to do that in several places for different reasons.
Can you suggest any better solution or work around for that?

Was this page helpful?
0 / 5 - 0 ratings