- Timestamp:
- 11/16/04 14:00:41 (20 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changes
r23 r24 9 9 * allow option lists to have simple multiword and quoted 10 10 string values 11 * allow for validated but not required fields 11 12 12 13 0.05 - 9 Nov 2004 -
trunk/lib/Text/FormBuilder.pm
r23 r24 83 83 } 84 84 } 85 }86 87 # remove extraneous undefined values88 for my $field (@{ $self->{form_spec}{fields} }) {89 defined $$field{$_} or delete $$field{$_} foreach keys %{ $field };90 85 } 91 86 … … 145 140 } 146 141 147 142 # remove extraneous undefined values 143 for my $field (@{ $self->{form_spec}{fields} }) { 144 defined $$field{$_} or delete $$field{$_} foreach keys %{ $field }; 145 } 146 147 # because this messes up things at the CGI::FormBuilder::field level 148 # it seems to be marking required based on the existance of a 'required' 149 # param, not whether it is true or defined 150 $$_{required} or delete $$_{required} foreach @{ $self->{form_spec}{fields} }; 148 151 149 152 150 153 $self->{form} = CGI::FormBuilder->new( 151 154 %DEFAULT_OPTIONS, 155 required => [ map { $$_{name} } grep { $$_{required} } @{ $self->{form_spec}{fields} } ], 152 156 title => $self->{form_spec}{title}, 153 157 template => { … … 218 222 %DEFAULT_OPTIONS, 219 223 title => $self->{form_spec}{title}, 224 required => [ map { $$_{name} } grep { $$_{required} } @{ $self->{form_spec}{fields} } ], 220 225 template => { 221 226 type => 'Text', … … 327 332 $OUT .= (grep { $$_{invalid} } @group_fields) ? qq[ <tr class="invalid">\n] : qq[ <tr>\n]; 328 333 329 330 334 #TODO: validated but not required fields 331 335 # in a form spec: //EMAIL? 332 336 333 #TODO: this doesn't seem to be working; all groups are getting marked as required334 337 $OUT .= ' <th class="label">'; 335 338 $OUT .= (grep { $$_{required} } @group_fields) ? qq[<strong class="required">$$line[1]{label}:</strong>] : "$$line[1]{label}:"; … … 362 365 td ul { list-style: none; padding-left: 0; margin-left: 0; } 363 366 .sublabel { color: #999; } 367 .invalid { background: red; } 364 368 </style> 365 369 </head> … … 586 590 =head2 Fields 587 591 588 Form fields are each described on a single line. The simplest field is just a 589 name: 592 First, a note about multiword strings in the fields. Anywhere where it says 593 that you may use a multiword string, this means that you can do one of two 594 things. For strings that consist solely of alphanumeric characters (i.e. 595 C<\w+>) and spaces, the string will be recognized as is: 596 597 field_1|A longer label 598 599 If you want to include non-alphanumerics (e.g. punctuation), you must 600 single-quote the string: 601 602 field_2|'Dept./Org.' 603 604 To include a literal single-quote in a single-quoted string, escape it with 605 a backslash: 606 607 field_3|'\'Official\' title' 608 609 Now, back to the basics. Form fields are each described on a single line. 610 The simplest field is just a name (which cannot contain any whitespace): 590 611 591 612 color … … 597 618 color|Favorite color 598 619 599 Field names cannot contain whitespace, but the descriptive label can.620 The descriptive label can be a multiword string, as described above. 600 621 601 622 To use a different input type: … … 629 650 color|Favorite color:select{red,blue,green} 630 651 631 Values are in a comma-separated list inside curly braces. Whitespace 632 between values is irrelevant, although there cannot be any whitespace 633 within a value. 652 Values are in a comma-separated list of single words or multiword strings 653 inside curly braces. Whitespace between values is irrelevant. 634 654 635 655 To add more descriptive display text to a vlaue in a list, add a square-bracketed … … 637 657 638 658 ...:select{red[Scarlet],blue[Azure],green[Olive Drab]} 639 640 As you can see, spaces I<are> allowed within the display text for a value.641 659 642 660 If you have a list of options that is too long to fit comfortably on one line, … … 661 679 { value2 => 'Description 2}, ... ) >> form. 662 680 663 B<NOTE:> This feature of the language may go away unless I find a compelling681 I<B<NOTE:> This feature of the language may go away unless I find a compelling 664 682 reason for it in the next few versions. What I really wanted was lists that 665 683 were filled in at run-time (e.g. from a database), and that can be done easily 666 enough with the CGI::FormBuilder object directly. 684 enough with the CGI::FormBuilder object directly.> 667 685 668 686 You can also supply a default value to the field. To get a default value of … … 670 688 671 689 color|Favorite color:select=green{red,blue,green} 690 691 Default values can also be either single words or multiword strings. 672 692 673 693 To validate a field, include a validation type at the end of the field line: … … 687 707 title//VALUE 688 708 709 By default, adding a validation type to a field makes that field required. To 710 change this, add a C<?> to the end of the validation type: 711 712 contact//EMAIL? 713 714 In this case, you would get a C<contact> field that was optional, but if it 715 were filled in, would have to validate as an C<EMAIL>. 716 689 717 =head2 Comments 690 718 … … 702 730 with their own id and (optional) heading 703 731 704 Optional validated fields; marked like C<//EMAIL?>705 706 732 Better examples in the docs (maybe a standalone or two as well) 707 733 -
trunk/lib/Text/FormBuilder/grammar
r23 r24 14 14 $type, 15 15 @options, 16 $required, 16 17 $list_var, 17 18 $size, … … 105 106 list => $list_var, 106 107 validate => $item{'validate(?)'}[0], 108 required => $required || 0, 107 109 }; 108 110 … … 121 123 } 122 124 125 #warn "field $item{name} is required" if $required; 126 123 127 $type = undef; 128 $required = 0; 124 129 $list_var = undef; 125 130 $size = undef; … … 164 169 list_var: /@[A-Z_]+/ { $list_var = $item[1] } 165 170 166 option: ( simple_multiword | quoted_string) display_text(?)171 option: (value | simple_multiword | quoted_string) display_text(?) 167 172 { push @options, { $item[1] => $item{'display_text(?)'}[0] } } 168 173 … … 171 176 display_text: '[' /[^\]]+/i ']' { $item[2] } 172 177 173 validate: '//' value 178 validate: '//' (optional_pattern | required_pattern) { $item[2] } 179 180 optional_pattern: /[A-Z_]+/ '?' { $required = 0; $item[1] } 181 182 required_pattern: /[A-Z_]+/ { $required = 1; $item[1] } 174 183 175 184 comment: '#' /.*/
Note: See TracChangeset
for help on using the changeset viewer.