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 2010/06/23 14:35:14 UTC

form package

In the process of documenting the 'form' package I found a few things that
looked like small bugs.

 - the 'field' method should treat checkbox and radiobuttons alike, printing
the label for the button 

 - the -labels switch in the radiobuttons menthod shouldn't propagate to the
html attributes, IMO.

 - a few comments have been corrected: they were cut and paste of other comments

below the differences

I also think that the class should be reformed allowing a more flexible use.
I'm probably pondering too much about some details, but I don't like the way
'form' leaves you with the only option of sending the html to the client as
object methods are invoked. Rivet Channel does that, it simply wraps ap_rputs
within a tcl 'puts' command with no buffering and, first of all, no xml
awareness. 

I took the habit of sending xml code down the output chain in a consistent and
controlled way, presuming the pipelining of xml text by processors that might
be downstream could benefit from the fact that xml fragments are already well
formed and not too small. Experts in xml processors internals would have a
better opinion on this and I'd like to know what they think.

In general, I'd like to have the option of creating content generators that
send data in a controlled way, something like

form myform ....

set xmlcode [myform start ....]
append xmlcode [myform text ...]
append xmlcode [myform submit ....]
append xmlcode [myform end]

puts $xmlcode 

Perhaps it's too late to merge the 2 approaches, but I wanted to
bring up the issue anyway 

 -- Massimo

Index: rivet/packages/form/form.tcl
===================================================================
--- rivet/packages/form/form.tcl	(revision 956657)
+++ rivet/packages/form/form.tcl	(working copy)
@@ -102,7 +102,7 @@
 	foreach {var val} $list {
 	    set var [string range [string tolower $var] 1 end]
 	    set data($var) $val
-	    if {$var == "values"} { continue }
+	    if {($var == "values") || ($var == "labels")} { continue }
 	    lappend return -$var $val
 	}
 	return $return
@@ -223,7 +223,7 @@
 	append string " />"
 
 	# ...and emit it
-	if {$type == "radio"} {
+	if {($type == "radio") || ($type == "checkbox")} {
 	    html $string$data(label)
 	} else {
 	    html $string
@@ -273,14 +273,14 @@
     }
 
     #
-    # reset -- emit an HTML image field
+    #  image -- emit an HTML image field
     #
     method image {name args} {
 	eval field image $name $args
     }
 
     #
-    # reset -- emit an HTML "checkbox" form field
+    # checkbox -- emit an HTML "checkbox" form field
     #
     method checkbox {name args} {
 	eval field checkbox $name $args


--


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


Re: form package

Posted by Massimo Manghi <ma...@unipr.it>.
I overlooked another point where radiobuttons and checkboxes were not handled
alike (and I think they should)

-- Massimo

Index: rivet/packages/form/form.tcl
===================================================================
--- rivet/packages/form/form.tcl	(revision 956657)
+++ rivet/packages/form/form.tcl	(working copy)
@@ -102,7 +102,7 @@
 	foreach {var val} $list {
 	    set var [string range [string tolower $var] 1 end]
 	    set data($var) $val
-	    if {$var == "values"} { continue }
+	    if {($var == "values") || ($var == "labels")} { continue }
 	    lappend return -$var $val
 	}
 	return $return
@@ -214,7 +214,7 @@
 		# and it matches the value we have for it, make
 		# the field show up as selected (checked)
 		if {[info exists DefaultValues($name)]} {
-		    if {$data(value) == $DefaultValues($name)} {
+		    if {[lsearch $DefaultValues($name) $data(value)] >= 0} {			
 			append string { checked="checked"}
 		    }
 		}
@@ -223,7 +223,7 @@
 	append string " />"
 
 	# ...and emit it
-	if {$type == "radio"} {
+	if {($type == "radio") || ($type == "checkbox")} {
 	    html $string$data(label)
 	} else {
 	    html $string
@@ -273,14 +273,14 @@
     }
 
     #
-    # reset -- emit an HTML image field
+    #  image -- emit an HTML image field
     #
     method image {name args} {
 	eval field image $name $args
     }
 
     #
-    # reset -- emit an HTML "checkbox" form field
+    # checkbox -- emit an HTML "checkbox" form field
     #
     method checkbox {name args} {
 	eval field checkbox $name $args



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