Gossamer Forum
Home : Gossamer Threads Inc. : Discussion :

GT::SQL::HTML::Display

Quote Reply
GT::SQL::HTML::Display
It would be cool if GT could finish up the docs for this module =(

I'm trying to create a select list as follows:

Code:
$html->select(
{
name => 'Days',
values => \%days,
multiple => 4,
blank => 0,
value => \@days,
sort => sub {
?
}
}
);

I'd like to sort the list numerically as at the moment it is jumbled. I'm not really clear on what should go inside the sort code ref.

Thanks.

Last edited by:

Paul: Apr 9, 2003, 4:16 AM
Quote Reply
Re: [Paul] GT::SQL::HTML::Display In reply to
I hear your call for docs; it is, however, documented in the subroutine comments (but should be in the POD, I agree):

Code:
# Make a select list. Valid options are:
# name => FORM_NAME
# values => { form_value => displayed_value }
# value => selected_value
# or
# value => [selected_value1, selected_value2]
# multiple => n - adds MULTIPLE SIZE=n to select list
# sort => coderef called to sort the list or array ref specifying the order in
# which the fields should be display. A code ref, when called, will be
# passed the following arguments: ($value{$a}, $value{$b}, $a, $b)
# blank => 1 or 0. If true, a blank first option will be printed, if false
# the blank first element will not be printed. Defaults to true.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] GT::SQL::HTML::Display In reply to
Yeah I saw that, but didn't really get it. Are all four of those parameters passed to the subroutine?

When I dumped @_ it gave me two pairs of the same value. 12 21 12 21 - the select list contains all numbers from 1 - 31
Quote Reply
Re: [Paul] GT::SQL::HTML::Display In reply to
I think that the first two are the displayed values, and the second two are the form values. So, when the sort compares what will become:

<option value="f">Foo</option>
<option value="b">Bar</option>

You should get @_ = ("Foo, "Bar", "f", "b") in the sort code. (But play around with dumping the values just to make sure)

There's also some undocumented support to pass in an array reference for the sort value; in the above example, passing in ['f', 'b'] would put them in the order shown above.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] GT::SQL::HTML::Display In reply to
Ah right, that may be easiest then...so I could do this?

sort => [ 1..31 ]
Quote Reply
Re: [Paul] GT::SQL::HTML::Display In reply to
Yes, I think so Angelic

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] GT::SQL::HTML::Display In reply to
Edit: Nevermind.

Last edited by:

Paul: Apr 11, 2003, 3:15 AM
Quote Reply
Re: [Jagerman] GT::SQL::HTML::Display In reply to
Finally figured this out. You can get a select list to sort alphabetically by passing the following option into $html->select():

Code:
sort => sub {
my ($aa, $bb) = @_;
return lc($aa) cmp lc($bb);
}