~ubuntu-branches/ubuntu/edgy/libcgi-formbuilder-perl/edgy

« back to all changes in this revision

Viewing changes to lib/CGI/FormBuilder/Field/static.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2006-05-28 15:47:27 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060528154727-u26u5nqd0btamxpm
Tags: 3.03.01-1
* New upstream release.
  + optgroups bugfix for complex arrays.
  + removal of HTML::Entities support due to utf8 issues. Closes:
    bug#338369 (thanks to Todd Charron <tcharron@badkarma.mine.nu> for
    reporting, and to several others for working on workarounds).
  + new es_ES Messages module with better translations
  + a patch from Mark Hedges to enable plugin modules for mailresults()
* Update local cdbs snippet copyright-check.mk:
  + Broaden scan to also look for "(c)" by default.
  + Make egrep options configurable.
* Bump up standards-version to 3.7.2 (no changes needed).
* Update debian/copyright_hints (nothing remarkable).
* Bump up debian/watch to version 3 syntax, and use uversionmangle
  instead of multiple parantheses (both work using uscan locally, but
  the later hopefully works with qa.debian.org too).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
package CGI::FormBuilder::Field::static;
 
3
 
 
4
=head1 NAME
 
5
 
 
6
CGI::FormBuilder::Field::static - FormBuilder class for static fields
 
7
 
 
8
=head1 SYNOPSIS
 
9
 
 
10
    use CGI::FormBuilder::Field;
 
11
 
 
12
    # delegated straight from FormBuilder
 
13
    my $f = CGI::FormBuilder::Field->new($form,
 
14
                                         name => 'whatever',
 
15
                                         type => 'static');
 
16
 
 
17
=cut
 
18
 
 
19
use strict;
 
20
 
 
21
our $VERSION = '3.03';
 
22
 
 
23
use CGI::FormBuilder::Util;
 
24
use CGI::FormBuilder::Field;
 
25
use base 'CGI::FormBuilder::Field';
 
26
 
 
27
# The majority of this module's methods (including new) are
 
28
# inherited directly from ::base, since they involve things
 
29
# which are common, such as parameter parsing. The only methods
 
30
# that are individual to different fields are those that affect
 
31
# the rendering, such as script() and tag()
 
32
 
 
33
sub script {
 
34
    return '';        # static fields get no messages
 
35
}
 
36
 
 
37
*render = \&tag;
 
38
sub tag {
 
39
    local $^W = 0;    # -w sucks
 
40
    my $self = shift;
 
41
    my $attr = $self->attr;
 
42
 
 
43
    my $jspre = $self->{_form}->jsprefix;
 
44
 
 
45
    my @tag;
 
46
    my @value = $self->tag_value;   # sticky is different in <tag>
 
47
    my @opt   = $self->options;
 
48
    debug 2, "my(@opt) = \$field->options";
 
49
 
 
50
    # Add in our "Other:" option if applicable
 
51
    push @opt, [$self->othername, $self->{_form}{messages}->form_other_default]
 
52
             if $self->other;
 
53
 
 
54
    debug 2, "$self->{name}: generating $attr->{type} input type";
 
55
 
 
56
    # static fields are actually hidden
 
57
    $attr->{type} = 'hidden';
 
58
 
 
59
    # We iterate over each value - this is the only reliable
 
60
    # way to handle multiple form values of the same name
 
61
    # (i.e., multiple <input> or <hidden> fields)
 
62
    @value = (undef) unless @value; # this creates a single-element array
 
63
 
 
64
    for my $value (@value) {
 
65
        my $tmp = '';
 
66
 
 
67
        # setup the value
 
68
        $attr->{value} = $value;      # override
 
69
        delete $attr->{value} unless defined $value;
 
70
 
 
71
        # render the tag
 
72
        $tmp .= htmltag('input', $attr);
 
73
 
 
74
        #
 
75
        # If we have options, lookup the label instead of the true value
 
76
        # to print next to the field. This will happen when radio/select
 
77
        # lists are converted to 'static'.
 
78
        #
 
79
        for (@opt) {
 
80
            my($o,$n) = optval($_);
 
81
            if ($o eq $value) {
 
82
                $n ||= $attr->{labels}{$o} || ($self->nameopts ? toname($o) : $o);
 
83
                $value = $n;
 
84
                last;
 
85
            }
 
86
        }
 
87
 
 
88
        # print the value out too when in a static context
 
89
        $tmp .= escapehtml($value);
 
90
        push @tag, $tmp;
 
91
    }
 
92
 
 
93
    debug 2, "$self->{name}: generated tag = @tag";
 
94
    return join ' ', @tag;       # always return scalar tag
 
95
}
 
96
 
 
97
1;
 
98
 
 
99
__END__
 
100
 
 
101
=head1 DESCRIPTION
 
102
 
 
103
This module is used to create B<FormBuilder> elements of a specific type.
 
104
Currently, each type module inherits all of its methods from the main
 
105
L<CGI::FormBuilder::Field> module except for C<tag()> and C<script()>,
 
106
which affect the XHMTL representation of the field.
 
107
 
 
108
Please refer to L<CGI::FormBuilder::Field> and L<CGI::FormBuilder> for
 
109
documentation.
 
110
 
 
111
=head1 SEE ALSO
 
112
 
 
113
L<CGI::FormBuilder>, L<CGI::FormBuilder::Field>
 
114
 
 
115
=head1 REVISION
 
116
 
 
117
$Id: static.pm,v 1.12 2006/02/24 01:42:29 nwiger Exp $
 
118
 
 
119
=head1 AUTHOR
 
120
 
 
121
Copyright (c) 2005-2006 Nate Wiger <nate@wiger.org>. All Rights Reserved.
 
122
 
 
123
This module is free software; you may copy this under the terms of
 
124
the GNU General Public License, or the Artistic License, copies of
 
125
which should have accompanied your Perl kit.
 
126
 
 
127
=cut