infinitered / ProMotion-form

Deprecated -- use ProMotion-XLForm
19 stars 11 forks source link

Crash if you don't supply a :name #8

Closed markrickert closed 9 years ago

markrickert commented 9 years ago

App crashes with this error when you don't provide a :name attribute:

form.rb:52:in `input_data:': key not found (KeyError)
    from form.rb:31:in `block in fields'
    from form.rb:30:in `block in fields'
    from form.rb:27:in `fields'
    from form.rb:38:in `properties'
    from form.rb:13:in `build'
    from form_screen.rb:18:in `update_form_data'
    from form_screen.rb:8:in `viewDidLoad'

should :name be required?

jamonholmgren commented 9 years ago

I'm okay with removing the requirement. Should we fall back to using the label as the hash key when you call render_form? Or just skip it altogether?

markrickert commented 9 years ago

I think that leaving it out would be fine, but it turns out that FXForm requires it. We may have to fall back to a snake_cased label as a sensible default.

Most of the time, when using something like this to just display some data in fields or a button that does something, you won't need a key.

Also, why are we calling it :name when fxform calls it :key?

jamonholmgren commented 9 years ago

Also, why are we calling it :name when fxform calls it :key?

In an HTML form, input elements have a name (which becomes the key to the params hash in Rails), so I'm following that convention. One of the goals of ProMotion is to make it easy for Rails developers to transition, so it made sense to me to do that.

I'm cool with a snake_cased label as a default. Or even just use the label directly.

render_form
# => {
  "Email" => "jamon@clearsightstudio.com",
  "Phone" => "3601234567",
}

render_form["Phone Number"] # => "3601234567"

# etc
markrickert commented 9 years ago

Cool. patch with test coming soon.