Changeset 33779 for lang/perl/MENTA

Show
Ignore:
Timestamp:
06/04/09 13:11:42 (4 years ago)
Author:
kazuho
Message:

update HTML::AutoForm? in extlib to that of trunk

Location:
lang/perl/MENTA/trunk/extlib/HTML
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/MENTA/trunk/extlib/HTML/AutoForm.pm

    r25687 r33779  
    2727our $CLASS_PREFIX; 
    2828 
     29sub DEBUG () { $ENV{HTML_AUTOFORM_DEBUG} && 1 } 
     30 
    2931BEGIN { 
    3032    $VERSION = '0.01'; 
     
    7476        my $opts = $fields->[$i + 1]; 
    7577        die 'field type is missing or invalid' 
    76             unless $opts->{type} =~ /^(text|hidden|password|radio|select|checkbox|textarea)$/; 
     78            unless $opts->{type} =~ /^(text|hidden|password|radio|select|checkbox|textarea|file)$/; 
    7779        my $field_klass = 'HTML::AutoForm::Field::' . ucfirst $opts->{type}; 
    7880        push @{$self->{fields}}, $field_klass->new( 
     
    106108        '"', 
    107109        ($self->secure ? ' method="POST"' : ''), 
     110        ((grep {$_->type eq 'file'} @{$self->{fields}}) ? 
     111            ' enctype="multipart/form-data"' : ''), 
    108112        '>', 
    109113        '<table class="', 
     
    124128                ); 
    125129                if ($do_validate) { 
    126                     print STDERR "validating: ", $field->name, "\n"; 
    127130                    if (my $err = $field->validate($query)) { 
    128131                        push( 
     
    176179    for my $f (@{$self->{fields}}) { 
    177180        if (my $error = $f->validate($query)) { 
     181            print STDERR ( 
     182                'validation error:', $f->name, ':', $error->message, "\n", 
     183            ) if DEBUG; 
    178184            return; 
    179185        } elsif (my $h = $f->custom) { 
    180186            if (my $error = $h->($f, $query)) { 
     187                print STDERR ( 
     188                    'custom validation error:', $f->name, ':', $error->message, 
     189                    "\n", 
     190                ) if DEBUG; 
    181191                return; 
    182192            } 
     
    188198            if ($check_csrf_callback->($csrf_value)) { 
    189199                $ok = 1; 
     200            } else { 
     201                print STDERR 'csrf validation error:', "\n" 
     202                    if DEBUG; 
    190203            } 
     204        } else { 
     205            print STDERR 'no csrf key', "\n" 
     206                if DEBUG; 
    191207        } 
    192208        return 
    193209            unless $ok; 
    194210    } 
     211    print STDERR "no errors found in validation\n" 
     212        if DEBUG; 
    195213    1; 
    196214} 
     
    202220            ($_ => $base->{$_}) 
    203221        } grep { 
    204             ! exists $omit->{$_} && ! /^(allow_multiple|label|required)$/ 
     222            ! exists $omit->{$_} && ! /^(allow_multiple|label|required|xhtml_compat)$/ 
    205223        } keys %$base), 
    206224        %$extra, 
    207225    ); 
     226    my $is_xhtml = $base->{xhtml_compat}; 
    208227    my $html = join( 
    209228        '', 
    210229        '<' . $tag, 
    211230        (map { 
    212             ' ' . $_ . '="' . _escape_html($attr{$_}) . '"' 
     231            $is_xhtml || $_ ne $attr{$_} || 
     232            ! /^(?:(?:check|disable|select)ed|readonly)$/ 
     233                ? ' ' . $_ . '="' . _escape_html($attr{$_}) . '"' 
     234                : ' ' . $_; 
    213235        } sort grep { 
    214236            defined $attr{$_} 
    215237        } keys %attr), 
    216         defined $append ? ('>', $append, '</', $tag, '>') : ' />', 
     238        defined $append ? ('>', $append, '</', $tag, '>') : ($is_xhtml ? ' />' : '>'), 
    217239    ); 
    218240    $html; 
  • lang/perl/MENTA/trunk/extlib/HTML/AutoForm/Field.pm

    r25497 r33779  
    1515        custom         => undef, 
    1616        allow_multiple => undef, 
     17        xhtml_compat   => 1, 
    1718    ); 
    1819    Class::Accessor::Lite->mk_accessors(keys %Defaults); 
  • lang/perl/MENTA/trunk/extlib/HTML/AutoForm/Field/InputCheckable.pm

    r25497 r33779  
    3939                     ? grep { $_ eq $self->{value} } @$values 
    4040                         : $self->{checked}) 
    41                     ? (checked => 1) : (), 
     41                    ? (checked => 'checked') : (), 
    4242            }, 
    4343            { 
  • lang/perl/MENTA/trunk/extlib/HTML/AutoForm/Field/Option.pm

    r25497 r33779  
    66 
    77BEGIN { 
    8     Class::Accessor::Lite->mk_accessors(qw(value label selected)); 
     8    Class::Accessor::Lite->mk_accessors(qw(value label selected xhtml_compat)); 
    99}; 
    1010 
     
    2323        $self, 
    2424        ($values ? grep { $_ eq $self->{value} } @$values : $self->{selected}) 
    25             ? { selected => 1 } : {}, 
     25            ? { selected => 'selected' } : {}, 
    2626        { selected => 1 }, 
    2727        $self->{label}, 
  • lang/perl/MENTA/trunk/extlib/HTML/AutoForm/Field/Select.pm

    r25497 r33779  
    3030                %$attributes, 
    3131                value  => $value, 
     32                xhtml_compat => $self->xhtml_compat, 
    3233            ); 
    3334        }