Changeset 87 in text-formbuilder
- Timestamp:
- 06/29/05 16:02:34 (19 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changes
r85 r87 1 1 Release history for Text::FormBuilder. 2 2 3 0.12 4 * added !fb directive to set FB constructor parameters directly; 5 uses YAML to hold strucutred data 6 3 7 0.11 - 12 May 2005 4 8 * added support for the 'multiple' attribute on fields -
trunk/lib/Text/FormBuilder.pm
r85 r87 7 7 use vars qw($VERSION @EXPORT); 8 8 9 $VERSION = '0.1 1';9 $VERSION = '0.12_01'; 10 10 @EXPORT = qw(create_form); 11 12 #$::RD_TRACE = 1;13 11 14 12 use Carp; … … 288 286 } 289 287 288 my %fb_params; 289 if ($self->{form_spec}->{fb_params}) { 290 require YAML; 291 eval { %fb_params = %{ YAML::Load($self->{form_spec}->{fb_params}) } }; 292 if ($@) { 293 warn '[' . (caller(0))[3] . "] Bad !fb parameter block:\n$@"; 294 } 295 } 296 290 297 # gather together all of the form options 291 298 $self->{form_options} = { … … 314 321 }, 315 322 }, 316 %options, 323 #TODO: fields in fb_params are not getting recognized 324 %fb_params, # params from the formspec file 325 %options, # params from this method invocation 317 326 }; 318 327 … … 684 693 L<Class::Base> 685 694 695 You will also need L<YAML>, if you want to use the L<C<dump>|/dump> 696 method, or the L<C<!fb>|/!fb> directive in your formspec files. 697 686 698 =head1 DESCRIPTION 687 699 … … 1013 1025 =head2 Directives 1014 1026 1027 All directives start with a C<!> followed by a keyword. There are two types of 1028 directives: 1029 1030 =over 1031 1032 =item Line directives 1033 1034 Line directives occur all on one line, and require no special punctuation. Examples 1035 of line directives are L<C<!title>|/!title> and L<C<!section>|/!section>. 1036 1037 =item Block directives 1038 1039 Block directives consist of a directive keyword followed by a curly-brace delimited 1040 block. Examples of these are L<C<!group>|/!group> and L<C<!description>|/!description>. 1041 Some of these directives have their own internal structure; see the list of directives 1042 below for an explanation. 1043 1044 =back 1045 1046 And here is the complete list of directives 1047 1015 1048 =over 1016 1049 … … 1030 1063 =item C<!field> 1031 1064 1032 B<DEPRECATED> Include a named instance of a group defined with C<!group>. 1065 B<DEPRECATED> Include a named instance of a group defined with C<!group>. See 1066 L<Field Groups|/Field Groups> for an explanation of the new way to include 1067 groups. 1033 1068 1034 1069 =item C<!title> 1035 1070 1036 Title of the form.1071 Line directive contianing the title of the form. 1037 1072 1038 1073 =item C<!author> 1039 1074 1040 Author of the form.1075 Line directive naming the author of the form. 1041 1076 1042 1077 =item C<!description> 1043 1078 1044 A brief description of the form. Suitable for special instructions on how to 1045 fill out the form. 1079 A block directive containing a brief description of the form. Suitable for 1080 special instructions on how to fill out the form. All of the text within the 1081 block is folded into a single paragraph. 1046 1082 1047 1083 =item C<!section> 1048 1084 1049 Starts a new section. Each section has its own heading and id, which are 1050 written by defaultinto spearate tables.1085 A line directive that starts a new section. Each section has its own heading 1086 and id, which by default are rendered into spearate tables. 1051 1087 1052 1088 =item C<!head> 1053 1089 1054 Inserts a heading between two fields. There can only be one heading between 1055 any two fields; the parser will warn you if you try to put two headings right1056 next to each other.1090 A line directive that inserts a heading between two fields. There can only be 1091 one heading between any two fields; the parser will warn you if you try to put 1092 two headings right next to each other. 1057 1093 1058 1094 =item C<!note> 1059 1095 1060 A text note that can be inserted as a row in the form. This is useful for 1061 special instructions at specific points in a long form. 1096 A block directive containing a text note that can be inserted as a row in the 1097 form. This is useful for special instructions at specific points in a long form. 1098 Like L<C<!description>|/!description>, the text content is folded into a single 1099 paragraph. 1062 1100 1063 1101 =item C<!submit> 1064 1102 1065 A li st of one or more submit button labels in a comma-separated list. Each label1066 is a L<string|/Strings>. Multiple instances of this directive may be used; later 1067 lists are simply appended to the earlier lists. All the submit buttons are 1068 rendered together at the bottom of the form. See L<CGI::FormBuilder> for an1103 A line directive with one or more submit button labels in a comma-separated list. 1104 Each label is a L<string|/Strings>. Multiple instances of this directive may be 1105 used; later lists are simply appended to the earlier lists. All the submit buttons 1106 are rendered together at the bottom of the form. See L<CGI::FormBuilder> for an 1069 1107 explanation of how the multiple submit buttons work together in a form. 1070 1108 … … 1073 1111 =item C<!reset> 1074 1112 1075 The label for the a reset button at the end of the form. No reset button will be 1076 rendered unless you use this directive. 1113 Line directive giving a label for the a reset button at the end of the form. No 1114 reset button will be rendered unless you use this directive. 1115 1116 =item C<!fb> 1117 1118 The C<!fb> block directive allows you to include any parameters you want passed 1119 directly to the CGI::FormBuilder constructor. The block should be a hashref of 1120 parameters serialized as L<YAML>. Be sure to place the closing of the block on 1121 its own line, flush to the left edge, and to watch your indentation. Multiple 1122 C<!fb> blocks are concatenated, and the result is interpeted as one big chunk 1123 of YAML code. 1124 1125 !fb{ 1126 method: POST 1127 action: '/custom/action' 1128 javascript: 0 1129 } 1077 1130 1078 1131 =back … … 1080 1133 =head2 Strings 1081 1134 1082 First, a note about multiword strings in the fields. Anywhere where it says 1083 that you may use a multiword string, this means that you can do one of two 1084 things. For strings that consist solely of alphanumeric characters (i.e. 1085 C<\w+>) and spaces, the string will be recognized as is: 1135 Anywhere that it says that you may use a multiword string, this means you can 1136 do one of two things. For strings that consist solely of alphanumeric characters 1137 (i.e. C<\w+>) and spaces, the string will be recognized as is: 1086 1138 1087 1139 field_1|A longer label … … 1257 1309 } 1258 1310 1259 You can then include instances of this group using the C<!field> directive:1260 1261 !field %DATE birthday1262 1263 This will create a line in the form labeled `` Birthday'' which contains1311 You can also use groups in normal field lines: 1312 1313 birthday|Your birthday:DATE 1314 1315 This will create a line in the form labeled ``Your birthday'' which contains 1264 1316 a month dropdown, and day and year text entry fields. The actual input field 1265 1317 names are formed by concatenating the C<!field> name (e.g. C<birthday>) with … … 1268 1320 C<birthday_day>, and C<birthday_year>. 1269 1321 1270 You can also use groups in normal field lines:1271 1272 birthday|Your birthday:DATE1273 1274 1322 The only (currently) supported pieces of a fieldspec that may be used with a 1275 1323 group in this notation are name, label, and hint. 1324 1325 The old method of using field groups was with the C<!field> directive: 1326 1327 !field %DATE birthday 1328 1329 This format is now B<deprecated>, and the parser will warn you if you use it. 1276 1330 1277 1331 =head2 Comments … … 1297 1351 Make sure that multiple runs of the parser don't share data. 1298 1352 1299 Warn/suggest using the C<!submit> directive if some uses C<foo:submit>?1300 1301 Set FB constructor options directly in the formspec (via a C<!fb> or similar1302 directive). The major issue here would be what format to use to allow for1303 array/hash refs.1304 1305 1353 Pieces that wouldn't make sense in a group field: size, row/col, options, 1306 1354 validate. These should cause C<build> to emit a warning before ignoring them. … … 1325 1373 Creating two $parsers in the same script causes the second one to get the data 1326 1374 from the first one. 1375 1376 Placing C<fields> in a C<!fb> directive does not behave as expected (i.e. they 1377 don't show up). This is not a big issue, since you should be defining your fields 1378 in the body of the formspec file, but for completeness' sake I would like to get 1379 this figured out. 1327 1380 1328 1381 I'm sure there are more in there, I just haven't tripped over any new ones lately. :-) … … 1342 1395 sections. 1343 1396 1344 And of course, to Nathan Wiger, for giving us eCGI::FormBuilder in the1397 And of course, to Nathan Wiger, for giving us CGI::FormBuilder in the 1345 1398 first place. Thanks Nate! 1346 1399 -
trunk/lib/Text/FormBuilder/grammar
r84 r87 40 40 %formspec = (); # clear the old formspec data 41 41 } 42 (list_def | description_def | group_def | note | unknown_block_directive | line)(s)42 (list_def | description_def | group_def | note | fb_params | unknown_block_directive | line)(s) 43 43 { 44 44 # grab the last section, if there is any … … 53 53 54 54 $return = { 55 title => $formspec{title}, 56 author => $formspec{author}, 55 fb_params => $formspec{fb_params}, 56 title => $formspec{title}, 57 author => $formspec{author}, 57 58 description => $formspec{description}, 58 lists => \%lists,59 patterns => \%patterns,60 subs => \%subs,61 groups => \%groups,62 sections => \@sections,59 lists => \%lists, 60 patterns => \%patterns, 61 subs => \%subs, 62 groups => \%groups, 63 sections => \@sections, 63 64 ( @submit ? 64 65 (submit => @submit == 1 ? $submit[0] : \@submit) : 65 66 () 66 67 ), 67 reset => $formspec{reset},68 reset => $formspec{reset}, 68 69 } 69 70 } … … 173 174 group_name: /%[A-Z_]+/ 174 175 176 # parameters that get passed to the FB constructor; these are serialized in YAML 177 fb_params: '!fb' block 178 { $formspec{fb_params} .= $item{block}; } 179 175 180 field_group: name label(?) hint(?) group_type comment(?) 176 181 { … … 189 194 # this is the real heart of the thing 190 195 field: name field_size(?) growable(?) label(?) hint(?) type(?) multi(?) other(?) default(?) option_list(?) validate(?) comment(?) 191 { 196 { 192 197 my $field = { 193 198 name => $item{name}, -
trunk/t/Text-FormBuilder.t
r53 r87 6 6 # change 'tests => 1' to 'tests => last_test_to_print'; 7 7 8 use Test::More qw(no_plan); #tests => 6;8 use Test::More tests => 10; 9 9 BEGIN { use_ok('Text::FormBuilder'); }; 10 10 … … 39 39 is(keys %{ $form->fields }, 3, 'correct number of fields'); 40 40 41 ##my $p2 = Text::FormBuilder->parse_array([qw(code title semester instructor)]);42 ##is(keys %{ $p2->form->fields }, 4, 'correct number of fields from parse_array');43 # #$p2->write;41 my $p2 = Text::FormBuilder->parse_array([qw(code title semester instructor)]); 42 is(keys %{ $p2->form->fields }, 4, 'correct number of fields from parse_array'); 43 #$p2->write;
Note: See TracChangeset
for help on using the changeset viewer.