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...@unipr.it> on 2007/10/10 21:15:56 UTC

proposed changes for load_response

Patch that would turn current load_response into the version
proposed recently on rivet-dev.

 -- M

Index: rivet/rivet-tcl/load_response.tcl
===================================================================
--- rivet/rivet-tcl/load_response.tcl   (revision 578004)
+++ rivet/rivet-tcl/load_response.tcl   (working copy)
@@ -12,13 +12,17 @@
 proc load_response {{arrayName response}} {
     upvar 1 $arrayName response

-    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
-        }
+       if {[info exists response(__$var)]} {
+               # we have seen var multiple times already, add to the list
+               lappend response($var) $elem
+       } elseif {[info exists response($var)]} {
+               # second occurence of var,  convert response(var) list:
+               set response($var) [list $response($var) $elem]
+               set response(__$var) ""
+       } else {
+               # first time seeing this var
+               set response($var) $elem
+       }
     }
 }




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


Re: proposed changes for load_response

Posted by Massimo Manghi <ma...@unipr.it>.
the patch for the manual that explains how load_response works, please
comment before i commit it (I'm sure the English native speakers have
to say something...)

 -- Massimo


Index: rivet.xml
===================================================================
--- rivet.xml   (revision 584101)
+++ rivet.xml   (working copy)
@@ -914,7 +914,17 @@
       <refsect1>
        <title>Description</title>
        Load any form variables passed to this page into an
-       array.
+       array. If <command>load_response</command> is called without
+       arguments the array <option>response</option> is created in
+       the scope of the caller. If the variables var1,var2,var3...
+       having values val1,val2,val3... are passed to the page, the
+       resulting array will be a collection mapping var1,var2,var3...
+       to their corresponding values. <command>load_response</command>
+       was inspired by the same NeoWebScript procedure in the way
+       it deals with multiple assignements: if a variable
+       is assigned more than once the corresponding array element will be a
+       list of the values for the variable. This can be useful in the case
+       of forms with checkbox options that are given the same name.
       </refsect1>
     </refentry>



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