Eureka: Set baseValue on row without calling onChange callback?

Created on 29 Jun 2016  路  9Comments  路  Source: xmartlabs/Eureka

Is that possible currently?

onChange

Most helpful comment

If anyone else stumbles against this issue.
You can do the following:

form.delegate = nil
row.value = "Your value"
form.delegate = self

And this will skip the callback.
Please note that this is private stuff and is susceptible to change

All 9 comments

You mean changing the value of the row without calling onChange?
No it is not and why would you want that?

Was looking for the functionality that UITextField provides with it's delegate callbacks, with textField:shouldChangeCharactersInRange:replacementString , for example, the delegate method only is called when user action caused the textField's value to change.

In my use case, I'm using Rx to validate the user input (on a settings page), and on every user input, I mutate my preferences, which is binded to my UI like so:

switch preferences.presence {
        case .Off:
            form.rowByTag("presence_enabled")!.baseValue = false
        case .All:
            form.rowByTag("presence_enabled")!.baseValue = true
            form.rowByTag(Prefs.Presence.All.s)!.baseValue = true
            form.rowByTag(Prefs.Presence.Devices.s)!.baseValue = false
        case .Devices:
            form.rowByTag("presence_enabled")!.baseValue = true
            form.rowByTag(Prefs.Presence.All.s)!.baseValue = false
            form.rowByTag(Prefs.Presence.Devices.s)!.baseValue = true
        }

        switch preferences.notification {
        case .Off:
            form.rowByTag("notifications_enabled")!.baseValue = false
        case .All:
            form.rowByTag("notifications_enabled")!.baseValue = true
            form.rowByTag(Prefs.Notifications.All.s)!.baseValue = true
            form.rowByTag(Prefs.Notifications.Devices.s)!.baseValue = false
        case .Devices:
            form.rowByTag("notifications_enabled")!.baseValue = true
            form.rowByTag(Prefs.Notifications.All.s)!.baseValue = false
            form.rowByTag(Prefs.Notifications.Devices.s)!.baseValue = true
        }

        print(form.allRows)

        form.allRows.forEach { $0.updateCell() }

currently, I'm using onCellSelection for CheckRows and onChange for SwitchRows. I'd like to be able to loop over them, and I can't do that currently with different callback functions.

You can see in the definition of value that it will always call onChange when it changes unless the row does not belong to a form.

So that would not be possible unless some hacky code can avoid calling the didSet of value.

 public required init(tag: String?,value: T? = nil){
        super.init(tag: tag)
        self.value = value // this will not call the didSet method for sure
  }

i guess if you add the value in default init method by taking one more parameter as a optional and setting a value in in init method it won't call didSet for sure.

@AndrewSB Did you find a workaround for this?

@mats-claassen yeah! I started using onCellSelection instead of onChange to listen for new values

If anyone else stumbles against this issue.
You can do the following:

form.delegate = nil
row.value = "Your value"
form.delegate = self

And this will skip the callback.
Please note that this is private stuff and is susceptible to change

This feature would be cool, consider the following use case:
The switch activates some feature (sync photos), that can fail (e.g. access to photo gallery not granted). In this case it would be great to revert the state of the switch.
When I revert the rowValue in the callback, onChange is fired and a loop is started that would last forever of course. Any suggestions how to manage this?

@imaximix This was exactly what I needed to do, setting two DecimalRow instance values inter-dependently, changing one would change the other after some calculation, and vice versa. I didn't find an answer to this back then, so I created a custom row with two inputs, trying to handle navigation, styling, etc. It was all a mess. Now I got rid of all unnecessary code and nib files using your suggestion, thanks!

Was this page helpful?
0 / 5 - 0 ratings