Skip Menu |

This queue is for tickets about the Curses-UI CPAN distribution.

Report information
The Basics
Id: 5756
Status: resolved
Priority: 0/
Queue: Curses-UI

People
Owner: Nobody in particular
Requestors: dkampenhout [...] interland.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.92
Fixed in: (no value)



Subject: -selected option on -multi Listbox doesn't function as documented
Perl Version: perl 5.8.0 Distribution version: Curses::UI 0.92 OS: RedHat Linux 9 I have found that the -select option in -multi listbox does not work as documented. According to my understanding of the documentation, to have multiple boxes selected in a multiple select Listbox, one must pass the -selected option with a hash reference with keys containing the -values which should be selected, the value of these entries being true. I tested the function using the example demo-widgets code, modified as follows: diff demo-widgets.orig demo-widgets.changed 375a376 Show quoted text
> my $selected = {"1"=>1,"2"=>1,"3"=>1};
382a384 Show quoted text
> -selected => $selected,
According to the documentation, one would expect the entries for 1, 2, and 3 in this listbox would have an "X" indicating that they are selected. Instead, I found that entries 2,3,and 4 were selected. It appears that instead of using the hash key to determine which -values record entry is selected, the hash key is really selecting the corresponding array index from the -values array reference. This makes it hard to work with arbitrary data in a multi-selected Listbox.
From: dkampenhout [...] interland.com
I have fixed the code to Listbox.pm to correct the problem. You can use this code if you wish. I'll attach the updated Listbox.pm file, but here is the diff from the old one to my new one: # diff Listbox.pm.orig Listbox.pm 348a349 Show quoted text
> my $tval = $this->{-values}->[$i];
375c376 < and $this->{-selected}->{$i}) ) { --- Show quoted text
> and $this->{-selected}->{$tval}) ) {
395c396 < $this->{-selected}->{$i}) { --- Show quoted text
> $this->{-selected}->{$tval}) {
[guest - Mon Mar 22 09:08:37 2004]: Show quoted text
> Perl Version: perl 5.8.0 > Distribution version: Curses::UI 0.92 > OS: RedHat Linux 9 > > I have found that the -select option in -multi listbox does not work > as documented. According to my understanding of the documentation, > to have multiple boxes selected in a multiple select Listbox, one > must pass the -selected option with a hash reference with keys > containing the -values which should be selected, the value of these > entries being true. I tested the function using the example demo- > widgets code, modified as follows: > > diff demo-widgets.orig demo-widgets.changed > 375a376
> > my $selected = {"1"=>1,"2"=>1,"3"=>1};
> 382a384
> > -selected => $selected,
> > According to the documentation, one would expect the entries for 1, 2, > and 3 in this listbox would have an "X" indicating that they are > selected. Instead, I found that entries 2,3,and 4 were selected. It > appears that instead of using the hash key to determine which > -values record entry is selected, the hash key is really selecting > the corresponding array index from the -values array reference. > This makes it hard to work with arbitrary data in a multi-selected > Listbox. > >

Message body is not shown because it is too large.

[guest - Fri Mar 26 15:31:06 2004]: Show quoted text
> I have fixed the code to Listbox.pm to correct the problem. You can > use this > code if you wish. I'll attach the updated Listbox.pm file, but here
is Show quoted text
> the diff > from the old one to my new one:
I didn't have a look into this till now and it will last at least another two weeks until I find enough time to understand what's happening here. But changing behavior seems in general a bad idea as it may break existing code and that's what I try to avoid. In general, I tend to rather change the documentation and add a new method in order to get the requested behavior as to change an existing method where people rely on this "bug". Thanks for your input, anyway. I'll have a much close look into this in a few weeks.
I said a couple of weeks, so here we go :-) From the docs: "In case the -multi option is set, INDEX is a hash reference in which the keys are the indices of the -values which are selected and the values are any true value." So, if you do my $selected = {"1"=>1,"2"=>1,"3"=>1}; you of course select the second,third and fourth element in the list, as the -values list is 0 indexed. If you disagree, please reopen :-)
Thanks for the update :^) I can see how the documentation supports the current functionality. I suppose what I'm really asking for is a feature change. Take it or leave it, but I'll try to describe what I'm looking for: Rather than the keys indicating the indices of the -values which are selected, could it be possible for the keys to be the actual -value entry which is to be selected? [MARCUS - Thu Jul 22 08:43:24 2004]: Show quoted text
> I said a couple of weeks, so here we go :-) > > From the docs: > > "In case the -multi option is set, INDEX is a hash reference in > which the keys are the indices of the -values which are selected > and the values are any true value." > > So, if you do > my $selected = {"1"=>1,"2"=>1,"3"=>1}; > > you of course select the second,third and fourth element in the list, > as the -values list is 0 indexed. > > If you disagree, please reopen :-)
Sorry, but I think I have to disappoint you. No changes to documented behavior; would break to many old applications. So, just start counting at zero, like real men do :-) Have fun, thanks for your input Marcus