Page 1 of 1

Inputselect checkbox style - no selection act as cancel

Posted: 17 Aug 2014 15:19
by klownboy
Hi, I'm using an inputselect box with the "2" checkbox style and the script works fine if the user makes one or more selections or if they cancel by hitting ESC or the cancel button, but if I hit OK without a selection being made the script continues and does some nasty undesired stuff. I know you can combine styles and there's a style 128 which will return "0" if nothing is selected but that style is for returning the index, not the checkbox(s) return value. I want the OK button to essentially act like hitting cancel if the user hasn't selected anything. Am I missing something or do I have to provide a separate if statement after inputselect such that if the inputselect value is "" or "0" it will end the script or provide a message?

On a separate note, Don would it be possible for inputselect to get a ONLY ONE option, such that inputselect would only allow one selection. It would be especially nice in the checkbox style where if you clicked on a second checkbox the previous selection would be unselected. I think that would be a very handy option for many scripters in many scenarios. I've come across a few instances already where instead I've had to state, select only one.
Thanks Ken


Edit: I'm fine with simply providing an "end" or "if " statement if the return is null unless someone has a better way on my first point, but the second item actually would be useful. I know I could control that as well, but it's would be significantly better if the user was prevented from selecting more than one item. :)

Re: Inputselect checkbox style - no selection act as cancel

Posted: 19 Aug 2014 07:51
by highend
Hi Ken,
Am I missing something or do I have to provide a separate if statement after inputselect such that if the inputselect value is "" or "0" it will end the script or provide a message?
You have to check for an empty return string if you're using flag = 2 and no selection was made.
Imho the current behavior is ok, because hitting OK (even while no item is selected) shouldn't exit the whole script stack.

Re: Inputselect checkbox style - no selection act as cancel

Posted: 19 Aug 2014 13:15
by klownboy
Thanks highend, I did end up putting in a end true type statement if the string is "".

Concerning the second issue or should I say suggestion, I think it would be both a valuable and well used if inputselect had an "only one" option (i.e., click on a second item and the first selection is unselected). Having the user no choice but to select one item is much better than having to check later if the items selected are greater than "1".
Thanks,
Ken

Re: Inputselect checkbox style - no selection act as cancel

Posted: 19 Aug 2014 13:30
by TheQwerty
klownboy wrote:Concerning the second issue or should I say suggestion, I think it would be both a valuable and well used if inputselect had an "only one" option
That is the default behavior - if you don't want multiple selection don't use check boxes.

It would be highly unconventional to have check boxes and only allow one item to be selected. In that case it would make more sense to wish for a radio box style, but given the default behavior adding radio boxes would just be GUI clutter.

Re: Inputselect checkbox style - no selection act as cancel

Posted: 19 Aug 2014 13:41
by klownboy
TheQwerty wrote:That is the default behavior - if you don't want multiple selection don't use check boxes.
Now that was easy...I didn't know that since I've been always using checkboxe style nor did I notice that info in the help, but here it is in the title subject. I was too busy looking at the detailed information.
Pops a list of strings from which the selected one is returned.
Thanks TheQwerty for straightening me out.

Re: Inputselect checkbox style - no selection act as cancel

Posted: 19 Aug 2014 13:47
by bdeshi
You could also use a lookalike html form....
EDIT: only if exclusive checkbox selection is crucial.
Here's a quick demo:

Code: Select all

$c = html(<<<#htmlinput
<body style="background-color:#eee; font-family:sans-serif;font-size:12px">
<p><span style="font-weight:bold">Header</span><br>
Sub Header</p>
<form style="border:2px solid #aaa;background-color:white" method="get" action="xys:">
<input type="checkbox" name="1" value="optiontext1" onclick="xclude(this)">Option 1 title</input><br>
<input type="checkbox" name="2" value="optiontext2" onclick="xclude(this)">Option 2 title</input><br>
<input type="checkbox" name="3" value="optiontext3" onclick="xclude(this)">Option 3 title</input><br>
<input type="checkbox" name="4" value="optiontext4" onclick="xclude(this)">Option 4 title</input><br>
<input type="checkbox" name="5" value="optiontext5" onclick="xclude(this)">Option 5 title</input><br>
<input type="submit" value="OK"><input type="submit" value="Cancel">
</form>
<script>
function xclude(e){
 all=document.getElementsByTagName("input");t=all.length;
 for(i=0;i<t;i++){if(e.checked==true){chk=false}else{chk=true;}if(all[i]!=e){all[i].checked=chk;}}
}</script>#htmlinput);
 text "parse the selected item or index from html's return (below) (customizable):<crlf>$c";
[/size]Not much of a lookalike yet though. :) Plus you need to persuade users to click the buttons inside the html, instead of the outer close button... So, only if exclusive checkbox is crucial.

Re: Inputselect checkbox style - no selection act as cancel

Posted: 21 Aug 2014 17:10
by klownboy
Sammay, sorry I meant to thank you sooner for the html demo. Now that I've been straightened out on inputselect though, it looks like I can use it in the non-checkbox mode and all is well.
Thanks again,
Ken

Re: Inputselect checkbox style - no selection act as cancel

Posted: 21 Aug 2014 17:25
by bdeshi
No problem.
:)