You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by Massimo Manghi <ma...@biol.unipr.it> on 2007/02/15 11:45:26 UTC

using 'load_response' with checkboxes

Hi fellow tclers ,

I'm using 'load_response' to handle the data being passed in
by a form where several checkboxes are used. I don't know
if i'm using checkboxes in an orthodox way but I
would like to have a list containing the lines numbers
for which  the corresponding checkbox is checked.

'load_response' seemed to do it well at first.

load_response is a very simple procedure and basically
builds an array in this way 

    array set response {}

    foreach {var elem} [var all] {
        if {[info exists response($var)]} {
            set response($var) [list $response($var) $elem]
        } else {
            set response($var) $elem
        }
    }

I think the first branch in the if statement would be better as

set response($var) [concat $response($var) $elem]

the difference between [list ....] and  [concat ...] is lesson 2 of Tcl
and I'm sure you have already imagined the effects of having 'list'
instead of 'concat'

example: I want the element 'oid' of the response to be set with
the list of the "value"  attributes for which for checkbox is checked

   <input type="checkbox" name="oid" value="v1"> Line 1 </input><br/>
   <input type="checkbox" name="oid" value="v2"> Line 2 </input> <br/>
   <input type="checkbox" name="oid" value="v3"> Line 3 </input> <br/>
   <input type="checkbox" name="oid" value="v4"> Line 4 </input> <br/>
 
if 2 ckeckboxes are checked (say checkbox 1,3 ) the array element is

response(oid) = v1 v3

which is correct. When 3 checkboxes are checked (say 1,3,4) the array is

response(oid) = {v1 v3} v4

Having more checkboxes results in a proportionally convoluted
list of nested lists.

-- 
-- Massimo Manghi 

-- Dipartimento di Biologia Evolutiva e Funzionale 
-- Università degli Studi di Parma
-- Parco Area delle Scienze 11A - 43100 Parma


---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: using 'load_response' with checkboxes

Posted by Massimo Manghi <ma...@biol.unipr.it>.
ok, thanks. That is perfect, I didn't notice that [var ...] was
able to strip the whole list of values assigned to a single
parameter name..I thought that would have assigned different
values to the same variable, in the same way the command
"array set {var1 value1 var1 value2 var1 value3}" would do.
(I fixed it modifing load_response and making it a method
in the root class of my pages, the var solution is better though)

I have another problem now: i would like to implement
the server side connector for the fckeditor file browser.
The file browser wants to have xml messages sent with
Content-Type: text/xml  and Cache-Control set to no-cache.
I wasn't able to force these headers using

headers set ... and headers add...
(checked using the usual GET and HEAD command
line utilities)

whereas "headers redirect <uri>" works  perfectly.
Where did i get it wrong?

 -- Massimo

P.S. As an alternative: does anyone suggest a nice
file browser that possibly works out of the box?

David Welton wrote:
>> I'm using 'load_response' to handle the data being passed in
>> by a form where several checkboxes are used. I don't know
>> if i'm using checkboxes in an orthodox way but I
>> would like to have a list containing the lines numbers
>> for which  the corresponding checkbox is checked.
>>
>> 'load_response' seemed to do it well at first.
>
> Yes, unfortunately, this is a tricky problem.  Basically, with
> checkboxes and Tcl, you have absolutely no way at all of knowing
> whether the value is
>
> [list foo bar"]
>
> or "foo bar"
>
> So it's best to use the various [var] commands to explicitly request a
> list or not.
>
> I don't know if the archives are very easy to find, but I recall
> discussing this extensively many years ago.
>


-- 
-- Massimo Manghi 

-- Dipartimento di Biologia Evolutiva e Funzionale 
-- Università degli Studi di Parma
-- Parco Area delle Scienze 11A - 43100 Parma


---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: using 'load_response' with checkboxes

Posted by David Welton <da...@apache.org>.
> I'm using 'load_response' to handle the data being passed in
> by a form where several checkboxes are used. I don't know
> if i'm using checkboxes in an orthodox way but I
> would like to have a list containing the lines numbers
> for which  the corresponding checkbox is checked.
>
> 'load_response' seemed to do it well at first.

Yes, unfortunately, this is a tricky problem.  Basically, with
checkboxes and Tcl, you have absolutely no way at all of knowing
whether the value is

[list foo bar"]

or "foo bar"

So it's best to use the various [var] commands to explicitly request a
list or not.

I don't know if the archives are very easy to find, but I recall
discussing this extensively many years ago.

-- 
David N. Welton
 - http://www.dedasys.com/davidw/

Linux, Open Source Consulting
 - http://www.dedasys.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org