Debian Codegraph @

Embperl/Form/Control/inputjoin.pm

raw
1
2 ###################################################################################
3 #
4 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5 # Embperl - Copyright (c) 2008-2014 Gerald Richter
6 #
7 # You may distribute under the terms of either the GNU General Public
8 # License or the Artistic License, as specified in the Perl README file.
9 #
10 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 #
14 # $Id$
15 #
16 ###################################################################################
17
18 package Embperl::Form::Control::inputjoin ;
19
20 use strict ;
21 use base 'Embperl::Form::Control' ;
22
23 use Embperl::Inline ;
24
25 use vars qw{%fdat} ;
26
27 # ------------------------------------------------------------------------------------------
28 #
29 # init_data - daten aufteilen
30 #
31
32 sub init_data
33 {
34 my ($self, $req) = @_ ;
35
36 my $fdat = $req -> {docdata} || \%fdat ;
37 my $name = $self -> {name} ;
38 my $split = $self -> {split} || $self -> {join} ;
39 my $num = $self -> {numinputs} || 1 ;
40 my $i = 0 ;
41 my @vals = split /$split/, $fdat->{$name} ;
42 for (my $i = 0; $i < $num; $i++)
43 {
44 $fdat->{"$name-_-$i"} = $vals[$i] ;
45 }
46 }
47
48 # ------------------------------------------------------------------------------------------
49 #
50 # prepare_fdat - daten zusammenfuehren
51 #
52
53 sub prepare_fdat
54 {
55 my ($self, $req) = @_ ;
56
57 my $fdat = $req -> {form} || \%fdat ;
58 my $name = $self -> {name} ;
59 my $join = $self -> {join} ;
60 my $num = $self -> {numinputs} || 1 ;
61 my @vals ;
62 for (my $i = 0; $i < $num; $i++)
63 {
64 push @vals, $fdat->{"$name-_-$i"} ;
65 }
66 $fdat->{$name} = join ($join, @vals) ;
67 }
68
69
70
71 1 ;
72
73 __EMBPERL__
74
75 [# ---------------------------------------------------------------------------
76 #
77 # show_control - output the control
78 #]
79
80 [$ sub show_control ($self)
81
82 my $class = $self -> {class} ;
83 my $numinputs = $self -> {numinputs} ;
84 my $size = $self -> {size} ||= 80 / ($self -> {width} || 2) / $numinputs ;
85 my $sep = $self -> {separator} || ' ' ;
86 my $i = 0 ;
87 $]
88 [$ while ($i < $numinputs) $]
89 <input type="text" class="cBase cControl [+ $class +]" name="[+ $self->{name} +]-_-[+ $i +]"
90 [$if $size $]size="[+ $size +]"[$endif$]
91 [$if $self -> {maxlength} $]maxlength="[+ $self->{maxlength} +]"[$endif$]
92 [+ do { local $escmode = 0 ; $self -> {eventattrs} } +]>[+ $i + 1 < $numinputs?$sep:'' +]
93 [- $i++ -]
94 [$endwhile$]
95 [$endsub$]
96
97 __END__
98
99 =pod
100
101 =head1 NAME
102
103 Embperl::Form::Control::inputjoin - A number of text input controls inside an Embperl Form
104
105
106 =head1 SYNOPSIS
107
108 {
109 type => 'input',
110 text => 'blabla',
111 name => 'foo',
112 size => 10,
113 maxlength => 50,
114 numinputs => 4
115 }
116
117 =head1 DESCRIPTION
118
119 Used to create a number of input control inside an Embperl Form,
120 which contents are joined.
121 See Embperl::Form on how to specify parameters.
122
123 =head2 PARAMETER
124
125 =head3 type
126
127 Needs to be 'input'
128
129 =head3 name
130
131 Specifies the name of the control
132
133 =head3 text
134
135 Will be used as label for the text input control
136
137 =head3 size
138
139 Gives the size in characters
140
141 =head3 maxlength
142
143 Gives the maximum possible input length in characters
144
145 =head3 class
146
147 Alternative CSS class name
148
149 =head3 numinputs
150
151 Number of input boxes
152
153 =head3 join
154
155 Strings which is used to join the input fields
156
157 =head3 split
158
159 Regex which is used to split the data into the input fields.
160 Default is /join/
161
162 =head3 separator
163
164 String to display between the input boxes
165
166 =head1 Author
167
168 G. Richter (richter at embperl dot org)
169
170 =head1 See Also
171
172 perl(1), Embperl, Embperl::Form
173
174