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> with Markaby? Thanks, Thomas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/camping-list/attachments/20070503/8407f449/attachment.bin
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> > > with Markaby? > > Thanks, > Thomas > > ------------------------------------------------------------------------ > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-listSomething like this is maybe what you want: # form for selecting projects to backup. def _backup_projects_form if @res then b "Status:"; _status_type(@res[0]); p text(@res[1]) else span.warning do ''backing up a project can take several minutes'' end p ''Select project(s) to backup: ''; form :id => :backupprojects, :method => :post, :action => R(Backup) do tag! :select, :name => ''project_list'' do #,:multiple=>:multiple,:size=>10 _active_projects_list.each do |p| tag! :option, p end end br input :type => :submit, :value => ''Backup Selected Projects'' end end end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/camping-list/attachments/20070503/1e19adfe/attachment-0001.html
On 03/05/07, Thomas Weibel <ml at beeblebrox.net> wrote:> 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> > > with Markaby?This works for me (Markaby 0.5)... html = Markaby::Builder.new do select :name => ''character'' do option ''Marvin the paranoid Android'', :value => ''marvin'' option ''Arthur Dent'', :value => ''arthur'' option ''Zaphod Beeblebrox'', :value => ''zaphod'' option ''Tricia McMillan'', :value => ''trillian'' option ''Ford Prefect'', :value => ''ford'' end end
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/camping-list/attachments/20070504/2cf1ba43/attachment.html
Thanks for all your answers, I finally got it working. It''s a shame, Markaby is not documented more detailed. Thanks again, Thomas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/camping-list/attachments/20070504/de3d71fa/attachment.bin
On Fri, May 04, 2007 at 04:26:40PM +0200, Thomas Weibel wrote:> One more thing: How would I preselect a certain entry like this?option ''Marvin'', :value => "marvin", :selected => "selected" -- <http://necronomicorp.com/bct> -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://rubyforge.org/pipermail/camping-list/attachments/20070504/ffb6921b/attachment.bin
One more thing: How would I preselect a certain entry like this? <select name="character"> <option value="marvin" selected>Marvin the paranoid Android</option> <option value="arthur">Arthur Dent</option> <option value="zaphod">Zaphod Beeblebrox</option> </select> Thanks, Thomas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/camping-list/attachments/20070504/9bfd501e/attachment.bin
On Fri, 2007-05-04 at 16:26 +0200, Thomas Weibel wrote:> One more thing: How would I preselect a certain entry like this?Never mind, I figured it out: @roles.each { |k,v| if @user and @roles[@user.role].to_s == v.to_s option v.to_s, :value => k, :selected => "selected" else option v.to_s, :value => k end } Obviously, XHTML need "selected=''selected''" anyway. Thomas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/camping-list/attachments/20070504/b1835f9c/attachment.bin