Changeset 28 in text-formbuilder for trunk


Ignore:
Timestamp:
11/17/04 09:07:38 (20 years ago)
Author:
peter
Message:

fixed errors from undefined references
removed old field/heading code from grammar

Location:
trunk/lib/Text
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Text/FormBuilder.pm

    r26 r28  
    66use vars qw($VERSION); 
    77 
    8 $VERSION = '0.06_01'; 
     8$VERSION = '0.06_02'; 
    99 
    1010use Carp; 
     
    1212use CGI::FormBuilder; 
    1313 
    14 # the default options passed to CGI::FormBuilder->new 
     14# the static default options passed to CGI::FormBuilder->new 
    1515my %DEFAULT_OPTIONS = ( 
    1616    method => 'GET', 
     
    7777     
    7878    # substitute in custom pattern definitions for field validation 
    79     if (my %patterns = %{ $self->{form_spec}{patterns} }) { 
     79    if (my %patterns = %{ $self->{form_spec}{patterns} || {} }) { 
    8080        foreach (@{ $self->{form_spec}{fields} }) { 
    8181            if ($$_{validate} and exists $patterns{$$_{validate}}) { 
     
    8585    } 
    8686     
    87 ##     # so we don't get all fields required 
    88 ##     foreach (@{ $self->{form_spec}{fields} }) { 
    89 ##         delete $$_{validate} unless $$_{validate}; 
    90 ##     } 
    91  
    9287    # expand groups 
    93     my %groups = %{ $self->{form_spec}{groups} }; 
    94     foreach (grep { $$_[0] eq 'group' } @{ $self->{form_spec}{lines} }) { 
     88    my %groups = %{ $self->{form_spec}{groups} || {} }; 
     89    foreach (grep { $$_[0] eq 'group' } @{ $self->{form_spec}{lines} || [] }) { 
    9590        $$_[1]{group} =~ s/^\%//;       # strip leading % from group var name 
    9691         
     
    107102     
    108103    $self->{form_spec}{fields} = []; 
    109     for my $line (@{ $self->{form_spec}{lines} }) { 
     104    for my $line (@{ $self->{form_spec}{lines} || [] }) { 
    110105        if ($$line[0] eq 'group') { 
    111106            push @{ $self->{form_spec}{fields} }, $_ foreach @{ $$line[1]{group} }; 
     
    117112     
    118113    # substitute in list names 
    119     my %lists = %{ $self->{form_spec}{lists} }; 
     114    my %lists = %{ $self->{form_spec}{lists} || {} }; 
    120115    foreach (@{ $self->{form_spec}{fields} }) { 
    121116        next unless $$_{list}; 
     
    169164            data => { 
    170165                lines       => $self->{form_spec}{lines}, 
    171                 headings    => $self->{form_spec}{headings}, 
    172166                author      => $self->{form_spec}{author}, 
    173167                description => $self->{form_spec}{description}, 
     
    215209    # don't dump $VARn names 
    216210    $Data::Dumper::Terse = 1; 
    217      
    218     my $title       = $self->{form_spec}{title} || ''; 
    219     my $author      = $self->{form_spec}{author} || ''; 
    220     my $description = $self->{form_spec}{description} || ''; 
    221      
    222     my $headings    = Data::Dumper->Dump([$self->{form_spec}{headings}],['headings']); 
    223     my $lines       = Data::Dumper->Dump([$self->{form_spec}{lines}],['lines']); 
    224     my $fields      = Data::Dumper->Dump([ [ map { $$_{name} } @{ $self->{form_spec}{fields} } ] ],['fields']); 
    225211     
    226212    my %options = ( 
     
    238224            data => { 
    239225                lines       => $self->{form_spec}{lines}, 
    240                 headings    => $self->{form_spec}{headings}, 
    241226                author      => $self->{form_spec}{author}, 
    242227                description => $self->{form_spec}{description}, 
     
    338323        $OUT .= (grep { $$_{invalid} } @group_fields) ? qq[  <tr class="invalid">\n] : qq[  <tr>\n]; 
    339324         
    340         #TODO: validated but not required fields 
    341         # in a form spec: //EMAIL? 
    342          
    343325        $OUT .= '    <th class="label">'; 
    344326        $OUT .= (grep { $$_{required} } @group_fields) ? qq[<strong class="required">$$line[1]{label}:</strong>] : "$$line[1]{label}:"; 
     
    740722=head1 TODO 
    741723 
    742 DWIM for single valued checkboxes (e.g. C<moreinfo|Send me more info:checkbox>) 
    743  
    744724Use the custom message file format for messages in the built in template 
    745725 
    746726C<!section> directive to split up the table into multiple tables, each 
    747727with their own id and (optional) heading 
     728 
     729Use HTML::Template instead of Text::Template for the built in template 
     730(since CGI::FormBuilder users may be more likely to already have HTML::Template) 
    748731 
    749732Better examples in the docs (maybe a standalone or two as well) 
  • trunk/lib/Text/FormBuilder/grammar

    r25 r28  
    88        %lists, 
    99        %patterns, 
    10         @fields, 
    1110        @group,        # current group 
    1211        %groups,       # stored groups of fields 
    13         @headings, 
    1412        $type, 
    1513        @options, 
     
    2321} 
    2422 
    25 form_spec: (list_def | description_def | group_def | line)(s)  
     23form_spec: (list_def | description_def | group_def | line)(s) 
    2624    { 
    2725        $return = { 
     
    2927            author   => $author, 
    3028            description => $description, 
    31             lists    => \%lists    || {},  
    32             patterns => \%patterns || {},  
    33             headings => \@headings || [], 
    34             fields   => \@fields   || [], 
    35             lines    => \@lines    || [], 
    36             groups   => \%groups   || {}, 
     29            lists    => \%lists, 
     30            patterns => \%patterns, 
     31            lines    => \@lines, 
     32            groups   => \%groups, 
    3733        } 
    3834    } 
     
    7167 
    7268title: '!title' /.*/ 
    73     { warn "[Text::Formbuilder] Title redefined at input text line $thisline\n" if defined $title; 
    74     $title = $item[2] } 
     69    { 
     70        warn "[Text::Formbuilder] Title redefined at input text line $thisline\n" if defined $title; 
     71        $title = $item[2]; 
     72    } 
    7573 
    7674author: '!author' /.*/ 
    77     { $author = $item[2] } 
     75    { 
     76        warn "[Text::Formbuilder] Author redefined at input text line $thisline\n" if defined $author; 
     77        $author = $item[2]; 
     78    } 
    7879 
    7980pattern_def: '!pattern' var_name pattern 
     
    8283pattern: /.*/ 
    8384 
    84 heading: '!head' /.*/ 
    85     { 
    86         warn "[Text::FormBuilder] Header before field " . scalar(@fields) . " redefined at input text line $thisline\n" if defined $headings[@fields]; 
    87         $headings[@fields] = $item[2]; 
    88         push @lines, [ 'head', $item[2] ]; 
    89     } 
     85heading: '!head' /.*/    { push @lines, [ 'head', $item[2] ] } 
    9086 
    9187group_field: '!field' group_name name label(?) 
    92     { #warn "[$thisline] $item{group_name}\n";  
    93     push @lines, [ 'group', { name => $item{name}, label => $item{'label(?)'}[0], group => $item{group_name} } ]; 
     88    {  
     89        push @lines, [ 'group', { name => $item{name}, label => $item{'label(?)'}[0], group => $item{group_name} } ]; 
    9490    } 
    9591 
     
    115111        $$field{size} = $size if defined $size; 
    116112         
    117         #warn "[$thisline] field $item{name}; context $context\n";    
     113        #warn "[$thisline] field $item{name}; context $context\n"; 
    118114        if ($context eq 'group') { 
    119115            push @group, $field; 
    120116        } else { 
    121             push @fields, $field; 
    122117            push @lines, [ 'field', $field ]; 
    123118        } 
    124          
    125         #warn "field $item{name} is required" if $required; 
    126119         
    127120        $type = undef; 
Note: See TracChangeset for help on using the changeset viewer.