Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: populating <select multi="1"> from ORM

by siracusa (Friar)
on Jul 06, 2007 at 01:37 UTC ( [id://625163]=note: print w/replies, xml ) Need Help??


in reply to populating <select multi="1"> from ORM

Have you considered using Rose::HTML::Objects? Here's a minimal, quick solution to your specific issue:

$field = Rose::HTML::Form::Field::SelectBox->new( name => 'whatever', multiple => 1, options => [ 1 => 'One', 2 => 'Two', 3 => 'Three' ], size => 3); $field->input_value([ 1, 3 ]); print $field->html;

or in TT-speak:

[% field.html %]

both of which produce:

<select multiple name="whatever" size="3"> <option selected value="1">1</option> <option value="One">One</option> <option value="2">2</option> <option value="Two">Two</option> <option selected value="3">3</option> <option value="Three">Three</option> </select>

You can manage your whole form using Rose::HTM::Objects as well, of course:

$form = Rose::HTML::Form->new; $form->add_fields ( whatever => { type => 'select box', multiple => 1, options => [ 1 => 'One', 2 => 'Two', 3 => 'Three' ], size => 3, }, ... ); # Pass in form params from various sources: # Hashref $form->params({ whatever => [ 1, 3 ] }); # CGI object $form->params_from_cgi($cgi); # $cgi "isa" CGI # Apache request object (mod_perl 1 or 2) $form->params_from_apache($r); # Initialize the fields based on params $form->init_fields();
Then, finally:
print $form->start_html, $form->field('whatever')->html, ... $form->end_html;

or in TT:

[% form.start_html %] [% form.field('whatever').html %] ... [% form.end_html %]

(For XHTML output, just replace the "html" method calls with "xhtml")

Yeah, I'm sure it looks "heavyweight", but life's too short to be manually producing form widget markup using TT, or any other templating language, IMO :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://625163]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2024-04-18 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found