Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: popup_menu labels bug?

by Errto (Vicar)
on Mar 26, 2006 at 16:40 UTC ( [id://539297]=note: print w/replies, xml ) Need Help??

in reply to popup_menu labels bug?

My guess is that the issue is that you're calling the value method in list context, and it's either is returning an empty list or a list of more than one element. As a result, popup_menu doesn't see any -labels argument and thus your popup menu has no labels.

One minor technical point for the record. The list of arguments you're passing to popup_menu is just a list, not a hash, but presumably that function just reads its arguments into a hash anyway, so the effect is the same.

Replies are listed 'Best First'.
Re^2: popup_menu labels bug?
by Thelonius (Priest) on Mar 26, 2006 at 17:21 UTC
    Errto has got it, I think!
    #!perl -w use CGI::Util qw(rearrange); sub showval { return defined($_[0])?$_[0]:"<undef>" } sub testcall { my (@p) = @_; my($name,$values,$default,$labels,$attributes,$override,$tabindex, +@other) = rearrange([NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LABELS, ATTRIBUTES,[OVERRIDE,FORCE],TABINDEX],@p); print "name = ", showval($name), "\n"; print "values = ", showval($values), "\n"; print "labels = ", showval($labels), "\n"; print "attributes = ", showval($attributes), "\n"; print "override = ", showval($override), "\n"; print "tabindex = ", showval($tabindex), "\n"; print "\@other = ", join(" ", @other), "\n"; } sub vooba { my @result = ("foo", "bar"); print "vooba: wantarray = ", wantarray, "\n"; return @result; } sub emptylist { my @result = (); return @result; } print "testcall1\n"; testcall( -name => "nameparm", -values => [ "array" ], -labels => "labels", -default => vooba(), ); print "\ntestcall2\n"; testcall( -name => "nameparm", -values => [ "array" ], -default => vooba(), -labels => "labels", ); print "\ntestcall3\n"; testcall( -name => "nameparm", -values => [ "array" ], -default => emptylist(), -labels => "labels", ); __END__
    testcall1 vooba: wantarray = 1 name = nameparm values = ARRAY(0x225848) labels = labels attributes = <undef> override = <undef> tabindex = <undef> @other = bar testcall2 vooba: wantarray = 1 name = nameparm values = ARRAY(0x225848) labels = <undef> attributes = <undef> override = <undef> tabindex = <undef> @other = bar="-labels" testcall3 name = nameparm values = ARRAY(0x225848) labels = <undef> attributes = <undef> override = <undef> tabindex = <undef> @other =
      Dead on guys. *sigh* Fixed with a simple scalar($_[0]->value)

      "One is enough. If you are acquainted with the principle, what do you care for the myriad instances and applications?"
      - Henry David Thoreau, Walden

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://539297]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-07-25 08:44 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.