Page 1 of 1
Bug with the 128 flag of inputselect
Posted: 09 Nov 2014 01:14
by klownboy
Help file for:
inputselect (header, listdata, [separator="|"], [style=1], [cancel], [width=600], [height=400], [windowcaption])
states,
128 = Return selected index. If nothing is selected, 0 (zero) is returned.
This statement is incorrect. When using return index "128", if the 1st item is selected, the return is "0", 2nd is "1", and 3rd item selected returns "2". If nothing is selected the return is
"-1". Which makes sense since it can't be "0" (zero) as stated since if the first item is selected the return is "0".
Edit: To make it easier to eval...
Code: Select all
$options = "One|Two|Three";
$index = inputselect("Select an option:<crlf>", "$options", "|" ,128, "None", 420, 265, "Your options");
if ($index == "0") {echo Index: $index}
if ($index == "1") {echo Index: $index}
if ($index == "2") {echo Index: $index}
if ($index == "-1") {msg "You haven't selected an option...aborting!"; end 1;}
Thanks,
Ken
Re: Website and Help Typos
Posted: 10 Nov 2014 08:11
by bdeshi
hmmm... that 128 flag also returns an extra space; it returns " 0", ..., " n" instead of "0", ..., "n".
(huh, a source code typo?)
Re: Website and Help Typos
Posted: 10 Nov 2014 10:05
by admin
SammaySarkar wrote:hmmm... that 128 flag also returns an extra space; it returns " 0", ..., " n" instead of "0", ..., "n".
(huh, a source code typo?)
Bingo!

Thanks.
Re: Website and Help Typos
Posted: 10 Nov 2014 10:06
by admin
klownboy wrote:Help file for:
inputselect (header, listdata, [separator="|"], [style=1], [cancel], [width=600], [height=400], [windowcaption])
states,
128 = Return selected index. If nothing is selected, 0 (zero) is returned.
This statement is incorrect. When using return index "128", if the 1st item is selected, the return is "0", 2nd is "1", and 3rd item selected returns "2". If nothing is selected the return is
"-1". Which makes sense since it can't be "0" (zero) as stated since if the first item is selected the return is "0".
Edit: To make it easier to eval...
Code: Select all
$options = "One|Two|Three";
$index = inputselect("Select an option:<crlf>", "$options", "|" ,128, "None", 420, 265, "Your options");
if ($index == "0") {echo Index: $index}
if ($index == "1") {echo Index: $index}
if ($index == "2") {echo Index: $index}
if ($index == "-1") {msg "You haven't selected an option...aborting!"; end 1;}
Thanks,
Ken
I think it was never intended to return the index 0-based. So the Help file is right but the code is wrong. Good find, thanks!
Re: Website and Help Typos
Posted: 10 Nov 2014 14:34
by TheQwerty
admin wrote:I think it was never intended to return the index 0-based. So the Help file is right but the code is wrong. Good find, thanks!
Sorry, I missed the cutoff for v14.50.0300, but for InputSelect...
Either style 128 needs to respect style 2 and return a list of the the checked items' indexes, or it needs to be documented that it will completely ignore the checkboxes and return the "selected" item's index.
It's rather obvious but it might also be worth mentioning that combining styles 16 and 128 will give you headaches.
Re: Website and Help Typos
Posted: 11 Nov 2014 09:09
by admin
TheQwerty wrote:admin wrote:I think it was never intended to return the index 0-based. So the Help file is right but the code is wrong. Good find, thanks!
Sorry, I missed the cutoff for v14.50.0300, but for InputSelect...
Either style 128 needs to respect style 2 and return a list of the the checked items' indexes, or it needs to be documented that it will completely ignore the checkboxes and return the "selected" item's index.
It's rather obvious but it might also be worth mentioning that combining styles 16 and 128 will give you headaches.
Hm,
style 2: I find the current behavior totally natural and expected. No need for docs.
style 16: The same. No headaches here.
Re: Website and Help Typos
Posted: 11 Nov 2014 13:41
by TheQwerty
admin wrote:TheQwerty wrote:Either style 128 needs to respect style 2 and return a list of the the checked items' indexes, or it needs to be documented that it will completely ignore the checkboxes and return the "selected" item's index.
It's rather obvious but it might also be worth mentioning that combining styles 16 and 128 will give you headaches.
style 2: I find the current behavior totally natural and expected. No need for docs.
style 16: The same. No headaches here.
Really? Even when those styles are combined with 128?
If you don't want to document it fine, and I'll grant you that it is obviously stupid to combine styles 16+128, but don't tell me that it's natural and expected that combining 2+128 completely ignores the checkboxes and only returns the focused item's index.
Please play with it a bit because frankly the behavior of 2+128 is completely baffling at first...
Code: Select all
"Styles 2+128" Echo InputSelect('Style is 2+128 so the checkboxes are ignored.', '+A|B|+C|D',, 2+128);
"Styles 16+128" Echo InputSelect('Style is 16+128 and since the user can reorder items, changing their indexes, the returned value is worthless.', 'A|B|C|D',, 16+128);
Re: Bug with the 128 flag of inputselect
Posted: 14 Nov 2014 09:34
by admin
Hm, I still find your example totally natural, normal, and expected. Maybe I'm spoilt.

Re: Bug with the 128 flag of inputselect
Posted: 17 Nov 2014 14:58
by TheQwerty
Must be!
When I use style 130 I'm all

Re: Bug with the 128 flag of inputselect
Posted: 17 Nov 2014 15:05
by admin
128 = Return selected index.
This has nothing to do with checked items.
Re: Bug with the 128 flag of inputselect
Posted: 17 Nov 2014 15:38
by TheQwerty
return The selected list item. If checkbox style then the checked items are returned, separated by separator.
2 means return the checked items.
128 means return the selected index.
130 means the checkboxes are displayed but completely meaningless as style 2 is ignored.
I doubt I'm the only one that expected and hoped that 130 would return a list of indexes of checked items.
16 means allow re-ordering items.
128 means return the selected index (after optional re-ordering).
144 means here's a random number between 0 and the count of items inclusive since you have no way of knowing if the items were re-ordered.
My point is the documentation is confusing because normally styles can be combined but here we have some styles that negate others and no idea how they are prioritized.
I've beaten this horse enough though so change it or not - I don't care.
Re: Bug with the 128 flag of inputselect
Posted: 17 Nov 2014 16:24
by admin
I added a note to the help.