Re: [cgiapp] Dropdown Menu
I find it works pretty well using TMPL_LOOP and an array of hashref's from the db - I loop through the data array and set the 'Selected' item before passing into the template, like so: in the viewer module: my $product_types = $self->dbh->selectall_arrayref("select * from product_type where ONIX_Code like 'B%'", { Slice => {} }); if ($data->{ProductTypeID}) { foreach my $row (@$product_types) { $row->{Selected} = 'selected' if $row->{ProductTypeID} eq $data->{ProductTypeID}; } } $template->params(product_types => $product_types); in the template: " > : mike On 14 April 2010 22:52, Adam wrote: > I want to have a dropdown menu that shows years 2000 thru 2015. I'm using > HTML::Template and I know I can pass an array ref to HTML::Template and loop > over it to make the menu, but how would I put in a "selected" year? What's > the best method? # CGI::Application community mailing list #### ## To unsubscribe, or change your message delivery options, ## ## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp## #### ## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ## ## Wiki: http://cgiapp.erlbaum.net/ ## ####
Re: [cgiapp] Dropdown Menu
On Wed, Apr 14, 2010 at 2:52 PM, Adam wrote: > I want to have a dropdown menu that shows years 2000 thru 2015. I'm using > HTML::Template and I know I can pass an array ref to HTML::Template and loop > over it to make the menu, but how would I put in a "selected" year? What's > the best method? I struggled with this when I first began using H::T. You need to add a "selected" hash item to the array ref. As you build the array ref, you have to ask "if current-year equal form-year, set selected = 1." Then, in your template you have to put inside the tmpl-loop, a selected="selected"> (I may have made a few typos in that example.). I thought this was unintuitive compared to how intuitive C::A and H::T are. It seemed like there should be a better way. But, after I got used to it, I obsessed about bigger and better things. I've never used fillnform. That might be a good suggestion. But, I wanted to make sure you know how to do it naively. Mark # CGI::Application community mailing list #### ## To unsubscribe, or change your message delivery options, ## ## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp## #### ## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ## ## Wiki: http://cgiapp.erlbaum.net/ ## ####
Re: [cgiapp] Dropdown Menu
On 04/14/2010 05:52 PM, Adam wrote: > I want to have a dropdown menu that shows years 2000 thru 2015. I'm using > HTML::Template and I know I can pass an array ref to HTML::Template and loop > over it to make the menu, but how would I put in a "selected" year? What's > the best method? For form filling, look at HTML::FillInForm. It's really fast and very flexible. I was amazed at how much complexity it removes from applications and templates. -- Michael Peters Plus Three, LP # CGI::Application community mailing list #### ## To unsubscribe, or change your message delivery options, ## ## visit: http://www.erlbaum.net/mailman/listinfo/cgiapp## #### ## Web archive: http://www.erlbaum.net/pipermail/cgiapp/ ## ## Wiki: http://cgiapp.erlbaum.net/ ## ####