On May 3, 2007, at 3:03 PM, Thomas Weibel wrote:

Hi

I couldn't figure out, how to create a drop-down list with Markaby. How
would I create something like this:

        <select name="character">
          <option value="marvin">Marvin the paranoid Android</option>
          <option value="arthur">Arthur Dent</option>
          <option value="zaphod">Zaphod Beeblebrox</option>
          <option value="trillian">Tricia McMillan</option>
          <option value="ford">Ford Prefect</option>
        </select>

Here's a helper method I use with Camping. You can pass in a simple array if your value matches your display text like ["value1", "value2", ...], or nested array pairs of [ ["value1", "display1"], ... ] if they don't.

def select_form(action, label_text, field_name, option_list, button_text = "Submit")
    form :action => action, :method => "post" do
      label label_text; br
      select :name => field_name do
        option_list.each do |value, text|
          option(text || value, :value => value)
        end
      end
      input :type => "submit", :value => button_text
    end
  end

Your example above would look something like:

  options = [ ["marvin", "Marvin the paranoid Android"],
    ["arthur", "Arthur Dent"], ... ]
select_form(R(MyController), "Select a hitchhiker:", "character", options)

It should also be easy to extract just the <select> portion. In fact I think I'll do that on my end too...

John

--
"The Internet is not something you just dump something
on.  It's not a big truck.  It's a series of tubes."
 --Senator Ted Stevens, R-AK

John R. Sheets
http://bark.metacasa.net



_______________________________________________
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to