[interchange-cvs] interchange - heins modified lib/Vend/Form.pm

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Fri Nov 8 12:28:00 2002


User:      heins
Date:      2002-11-08 17:27:24 GMT
Modified:  lib/Vend Form.pm
Log:
* Add new widget type, "fillin_combo", for surveys. (It is a very common
  survey question need to have "select one of the above or comment below".)

  Produces a select box with the options and provides a text input below
  (by default a textarea 2 rows 60 cols). Used in combination with the
  nullselect filter, and the "other" option should be a blank value.

Revision  Changes    Path
2.21      +29 -4     interchange/lib/Vend/Form.pm


rev 2.21, prev_rev 2.20
Index: Form.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Form.pm,v
retrieving revision 2.20
retrieving revision 2.21
diff -u -r2.20 -r2.21
--- Form.pm	30 Oct 2002 17:39:06 -0000	2.20
+++ Form.pm	8 Nov 2002 17:27:24 -0000	2.21
@@ -1,6 +1,6 @@
 # Vend::Form - Generate Form widgets
 # 
-# $Id: Form.pm,v 2.20 2002/10/30 17:39:06 mheins Exp $
+# $Id: Form.pm,v 2.21 2002/11/08 17:27:24 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -37,7 +37,7 @@
 require Exporter;
 @ISA = qw(Exporter);
 
-$VERSION = substr(q$Revision: 2.20 $, 10);
+$VERSION = substr(q$Revision: 2.21 $, 10);
 
 @EXPORT = qw (
 	display
@@ -548,8 +548,26 @@
 
 sub combo {
 	my ($opt, $opts) = @_;
-	my $addl = qq|<INPUT TYPE=text NAME="$opt->{name}"|;
-	$addl   .= qq| SIZE="$opt->{cols}" VALUE="">|;
+	my $addl;
+	if($opt->{textarea}) {
+		my $template = $opt->{o_template};
+		if(! $template) {
+			$template = '<br>';
+			if(! $opt->{rows} or $opt->{rows} > 1) {
+				$template .= q(<textarea rows="{ROWS|2}" wrap="{WRAP|virtual}");
+				$template .= q( cols="{COLS|60}" name="{NAME}">{ENCODED}</textarea>);
+			}
+			else {
+				$template .= qq(<input TYPE="text" size="{COLS|40}");
+				$template .= qq( name="{NAME}" value="{ENCODED}">);
+			}
+		}
+		$addl = attr_list($template, $opt);
+	}
+	else {
+		$addl = qq|<INPUT TYPE=text NAME="$opt->{name}"|;
+		$addl   .= qq| SIZE="$opt->{cols}" VALUE="">|;
+	}
 	if($opt->{reverse}) {
 		$opt->{append} = length($opt->{append}) ? "$addl$opt->{append}" : $addl;
 	}
@@ -1205,6 +1223,13 @@
 		$opt->{rows} = $opt->{rows} || $1 || 1;
 		$opt->{cols} = $opt->{cols} || $2 || 16;
 		$opt->{type} = 'combo';
+	}
+	elsif($type =~ /^fillin_combo[ _]*(?:(\d+)(?:[ _]+(\d+))?)?/i) {
+		$opt->{rows} ||= $1;
+		$opt->{cols} ||= $2;
+		$opt->{type} = 'combo';
+		$opt->{textarea} = 1;
+		$opt->{reverse} = 1;
 	}
 	elsif($type =~ /^reverse_combo[ _]*(?:(\d+)(?:[ _]+(\d+))?)?/i) {
 		$opt->{rows} = $opt->{rows} || $1 || 1;