Re: [htmltmpl] Select/option How to set "selected"?
Brought to you by:
samtregar
From: Sam T. <sa...@tr...> - 2004-05-04 05:47:29
|
On Mon, 3 May 2004, Mark Fuller wrote: > By way of suggestion, the way HTML::Template has various "__first__, > __last__, __counter__" helper fields, I wish there were a way to inform a > loop of a special value used to indicate the row that should get the > "selected" attribute. It seems like there's a lot of pragmatic helpers > available, but nothing for what is a very basic HTML construct. Why not a > reserved variable name like __selected__ and HTML::Template would fill it in > automatically if a corresponding boolean is true for that row? Would this be > any more efficient (or beautiful) than Puneet's suggestion? I don't think this is too much code to expect people to write: $row{__selected__} = "selected" if $value; That's really all you're talking about, right? > It just seems to me like "selected" and "checked" are fairly basic and > there's no easy (more built-in) way to accomodate them. It seems like you > recognize that they require a bit of ugliness. Why not provide for them > somehow? Because CGI.pm already has it nailed. Why reinvent the wheel? And you can't beat the simplicity: $template->param(year_select => scalar $query->popup_menu(-name => 'year', -values => [ 1970 .. 2020 ]) ); And in the template: <tmpl_var year_select> I've been doing it for years now and it's never done me wrong. -sam |