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 :)


In reply to Re: populating <select multi="1"> from ORM by siracusa
in thread populating <select multi="1"> from ORM by abs0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.