0
votes

I have a form that displays, and when i click the submit button it logs the values to the console.

How can i persist the settings so i can access them elsewhere in the application and the form is prepopulated when i return to the form screen?

I have my form set up like this

class ChimeScreen < FormotionScreen

  title "Chime"

  def on_submit(_form)
    data = _form.render

    # settings.enable = data[:enable]
    # settings.alarm_time = data[:alarm_time]
    PM.logger.debug data[:alarm_time]
    open BrowseScreen
  end

  def table_data
    {
      ...
    }
  end
2

2 Answers

1
votes

Formotion allows persistent data by setting the persist_as value on the form.

See example here: https://github.com/clayallsopp/formotion/tree/master/examples/Persistence

You can then retrieve this form data as a hash by looking into

App::Persistence["FORMOTION_#{your_symbol_persisting_as_here}"]
0
votes

OK, i think i was expecting something magical to set up there, when actually it's just straight forward value setting.

def on_submit(_form)
  data = _form.render
  @defaults = NSUserDefaults.standardUserDefaults
  unless data.nil?
    @defaults["alarm_time"] = data[:alarm_time]
    @defaults["alarm_enabled"] = data[:alarm_enabled]
  end
  open BrowseScreen
end

and then set the value for each form field...

def table_data
 @defaults = NSUserDefaults.standardUserDefaults
 {
  sections: [{
    title: "Set Daily Reminder",
    rows: [{
      title: "Enable",
      key: :alarm_enabled,
      type: :switch,
      value: @defaults["alarm_enabled"]
    },

...etc