bmichotte / ProMotion-XLForm

ProMotion-XLForm is a ProMotion plugin for XLForm
MIT License
20 stars 21 forks source link

Question: How to display data from CDQ model in selector #20

Closed Siggs2000 closed 9 years ago

Siggs2000 commented 9 years ago

I'm sure there's a way to do this but I can't seem to figure it out...

I have a model with certain city/state names like this: "Dallas, TX", "San Diego, CA", etc

And in a form selector (any type of selector will do) I'm trying something like this:

{
name: "region",
title: "Location",
type: :selector_push,
options: {
          AreaPlace.map do |place|
            "#{place.id}" => "#{place.name}"
          end
  }
}

But I get this syntax error:

syntax error, unexpected tASSOC, expecting keyword_end
            "#{place.id}" => "#{place.name}"
                           ^
/Users/sethsiegler/Dropbox/motion_stuff/fuse-ios/app/screens/registration_screen.rb:54: syntax error, unexpected '\n', expecting tASSOC
/Users/sethsiegler/Dropbox/motion_stuff/fuse-ios/app/screens/registration_screen.rb:73: syntax error, unexpected ']', expecting keyword_end
/Users/sethsiegler/Dropbox/motion_stuff/fuse-ios/app/screens/registration_screen.rb:142: syntax error, unexpected $end, expecting keyword_end
bmichotte commented 9 years ago

You should try this:

options: Hash[AreaPlace.map do |place|
            [place.id, place.name]
          end]

What it will do is the following

places = AreaPlace.map do |place|
     [place.id, place.name]
end
=> [["id_1", "Name1"], ["id_2", "Name2"], ["id_3", "Name3"]]

Hash[places]
=> {"id_1"=>"Name1", "id_2"=>"Name2", "id_3"=>"Name3"}
Siggs2000 commented 9 years ago

:+1: