- Timestamp:
- 11/17/04 11:16:57 (20 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changes
r24 r30 10 10 string values 11 11 * allow for validated but not required fields 12 * added a !section directive that splits up a form into 13 sub-tables with their own ids and captions 12 14 13 15 0.05 - 9 Nov 2004 -
trunk/lib/Text/FormBuilder.pm
r29 r30 18 18 keepextras => 1, 19 19 ); 20 21 # the built in CSS for the template 22 my $DEFAULT_CSS = <<END; 23 table { padding: 1em; } 24 #author, #footer { font-style: italic; } 25 caption h2 { padding: .125em .5em; background: #ccc; text-align: left; } 26 th { text-align: left; } 27 th h3 { padding: .125em .5em; background: #eee; } 28 th.label { font-weight: normal; text-align: right; vertical-align: top; } 29 td ul { list-style: none; padding-left: 0; margin-left: 0; } 30 .sublabel { color: #999; } 31 .invalid { background: red; } 32 END 20 33 21 34 sub new { … … 74 87 # form_only: use only the form part of the template 75 88 my $form_only = $options{form_only}; 76 delete $options{form_only}; 89 my $css; 90 $css = $options{css} || $DEFAULT_CSS; 91 $css .= $options{extra_css} if $options{extra_css}; 92 93 # remove our custom options 94 delete $options{$_} foreach qw(form_only css extra_css); 77 95 78 96 # substitute in custom pattern definitions for field validation … … 139 157 } continue { 140 158 delete $$_{list}; 141 } 159 } 160 161 # special case single-value checkboxes 162 foreach (grep { $$_{type} && $$_{type} eq 'checkbox' } @{ $self->{form_spec}{fields} }) { 163 unless ($$_{options}) { 164 $$_{options} = [ { $$_{name} => $$_{label} || ucfirst join(' ',split(/_/,$$_{name})) } ]; 165 } 166 } 142 167 143 168 # TODO: configurable threshold for this … … 167 192 engine => { 168 193 TYPE => 'STRING', 169 SOURCE => $form_only ? $self->_form_template : $self->_template ,194 SOURCE => $form_only ? $self->_form_template : $self->_template($css), 170 195 DELIMITERS => [ qw(<% %>) ], 171 196 }, … … 218 243 $Data::Dumper::Terse = 1; 219 244 245 my $css; 246 $css = $self->{build_options}{css} || $DEFAULT_CSS; 247 $css .= $self->{build_options}{extra_css} if $self->{build_options}{extra_css}; 248 220 249 my %options = ( 221 250 %DEFAULT_OPTIONS, … … 228 257 engine => { 229 258 TYPE => 'STRING', 230 SOURCE => $self->{build_options}{form_only} ? $self->_form_template : $self->_template ,259 SOURCE => $self->{build_options}{form_only} ? $self->_form_template : $self->_template($css), 231 260 DELIMITERS => [ qw(<% %>) ], 232 261 }, … … 242 271 my $source = $options{form_only} ? $self->_form_template : $self->_template; 243 272 244 delete $options{form_only}; 273 # remove our custom options 274 delete $options{$_} foreach qw(form_only css extra_css); 245 275 246 276 my $form_options = keys %options > 0 ? Data::Dumper->Dump([\%options],['*options']) : ''; … … 310 340 <% 311 341 SECTION: while (my $section = shift @sections) { 312 $OUT .= qq[<table id=" $$section{id}">\n];313 $OUT .= qq[ <caption><h2 >$$section{head}</h2></caption>] if $$section{head};342 $OUT .= qq[<table id="] . ($$section{id} || '_default') . qq[">\n]; 343 $OUT .= qq[ <caption><h2 class="sectionhead">$$section{head}</h2></caption>] if $$section{head}; 314 344 TABLE_LINE: for my $line (@{ $$section{lines} }) { 315 345 if ($$line[0] eq 'head') { 316 $OUT .= qq[ <tr><th class="s ectionhead" colspan="2"><h3>$$line[1]</h3></th></tr>\n]346 $OUT .= qq[ <tr><th class="subhead" colspan="2"><h3>$$line[1]</h3></th></tr>\n] 317 347 } elsif ($$line[0] eq 'field') { 318 348 #TODO: we only need the field names, not the full field spec in the lines strucutre … … 322 352 323 353 $OUT .= $$_{invalid} ? qq[ <tr class="invalid">] : qq[ <tr>]; 324 $OUT .= '<th class="label">' . ($$_{required} ? qq[<strong class="required">$$_{label}:</strong>] : "$$_{label}:") . '</th>'; 354 355 # special case single value checkboxes 356 if ($$_{type} eq 'checkbox' && @{ $$_{options} } == 1) { 357 $OUT .= qq[<th></th>]; 358 } else { 359 $OUT .= '<th class="label">' . ($$_{required} ? qq[<strong class="required">$$_{label}:</strong>] : "$$_{label}:") . '</th>'; 360 } 325 361 if ($$_{invalid}) { 326 $OUT .= qq[<td>$$_{field} $$_{comment} Missing or invalid value.</td> </tr>\n];362 $OUT .= qq[<td>$$_{field} $$_{comment} Missing or invalid value.</td>]; 327 363 } else { 328 $OUT .= qq[<td>$$_{field} $$_{comment}</td> </tr>\n];364 $OUT .= qq[<td>$$_{field} $$_{comment}</td>]; 329 365 } 366 $OUT .= qq[</tr>\n]; 367 330 368 } elsif ($$line[0] eq 'group') { 331 369 my @field_names = map { $$_{name} } @{ $$line[1]{group} }; … … 356 394 sub _template { 357 395 my $self = shift; 396 my $css = shift || $DEFAULT_CSS; 358 397 q[<html> 359 398 <head> 360 399 <title><% $title %><% $author ? ' - ' . ucfirst $author : '' %></title> 361 <style type="text/css"> 362 table { margin: .5em 1em; } 363 #author, #footer { font-style: italic; } 364 caption h2 { padding: .125em .5em; background: #ddd; text-align: left; } 365 th { text-align: left; } 366 th h3 { padding: .125em .5em; background: #eee; } 367 th.label { font-weight: normal; text-align: right; vertical-align: top; } 368 td ul { list-style: none; padding-left: 0; margin-left: 0; } 369 .sublabel { color: #999; } 370 .invalid { background: red; } 400 <style type="text/css">] . 401 $css . q[ 371 402 </style> 372 403 </head> … … 461 492 description as specified with the C<!description> directive. 462 493 494 =item C<css>, C<extra_css> 495 496 These options allow you to tell Text::FormBuilder to use different 497 CSS styles for the built in template. A value given a C<css> will 498 replace the existing CSS, and a value given as C<extra_css> will be 499 appended to the CSS. If both options are given, then the CSS that is 500 used will be C<css> concatenated with C<extra_css>. 501 463 502 =back 464 503 … … 703 742 moreinfo|I want to recieve more information:checkbox 704 743 705 The one drawback to this is that the label to the checkbox will still appear 706 to the left of the field. I am leaving it this way for now, but if enough 707 people would like this to change, I may make single-option checkboxes a special 708 case and put the label on the right. 744 In this case, the label ``I want to recieve more information'' will be 745 printed to the right of the checkbox. 709 746 710 747 You can also supply a default value to the field. To get a default value of … … 749 786 Use the custom message file format for messages in the built in template 750 787 751 Custom CSS, both in addition to, and replacing the built in. 752 753 Use HTML::Template instead of Text::Template for the built in template 788 Maybe use HTML::Template instead of Text::Template for the built in template 754 789 (since CGI::FormBuilder users may be more likely to already have HTML::Template) 755 790 … … 764 799 =head1 BUGS 765 800 766 For now, checkboxes with a single value still display their labels on 767 the left. 801 I'm sure they're in there, I just haven't tripped over any new ones lately. :-) 768 802 769 803 =head1 SEE ALSO
Note: See TracChangeset
for help on using the changeset viewer.