Background: Used raw DBI, CDBI, poked briefly at DBIC and now settled on Rose::DB::Object. All interfacing with web pages without any particular engine in the way/helping.
I've had a few web apps where I needed to present a list of options and show the selected option. Low volume sites, so all very easy to do with Template and something like:
<select name="whatever">
[% FOREACH option = whatever_options %]
<option value="[% option.value %]"
[% IF whatever == option.value %] selected="1" [% END %]>
[% option.name %]</option>
[% END %]
</select>
Now I've hit a case where I have a <select multi="1"> dialog, so obviously the above Does Not Work.
In perl I have a list of objects representing the possible values (lets say categories), and another list representing the values selected for the current viewed object (lets say an article).
Some paths:
- Create a third list, containing the possible objects with a new method 'selected' set for the objects selected.
- Add a 'selected' method to the ::Category class and go through setting as needed before passing to Template. I don't like this as I then need to discard the list after use rather than being able to cache between requests (mod_fcgid), but seems the 'least worst'
- Set some stupidly named values like 'cat'.$catid for each category set and test in Template (uh, no)
- Really clever and overly complicated logic in Template
I *have* to generate a sane single list and pass to Template, anything else is wrong, but I'm unsure as to the best way to deal with this.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.