File: edit_field_text_input

package info (click to toggle)
libalzabo-perl 0.92-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,200 kB
  • sloc: perl: 15,060; makefile: 4
file content (85 lines) | stat: -r--r--r-- 1,758 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<%doc>
=pod

=head1 NAME

edit_field_text_input

=head1 SYNOPSIS

  <& edit_field_text_input, column => $column, row => $row &>

=head1 DESCRIPTION

Given a column and an optional row, this component produces a text
input form element for that column.

If a row is given, then its value will be used as the default value
for the form element.

=head1 PARAMETERS

=over 4

=item * column (required)

An C<Alzabo::Column> object.

=item * row (optional)

An Alzabo row object.

=item * class (optional)

This defaults to C<<
$m->base_comp->attr_if_exists('text_input_class_default') >>, which
makes it easy to set up default styles for this form element.

=item * size (optional)

If this is not given, it default to C<<
$m->base_comp->attr_if_exists('text_input_size_default') >> if
available, otherwise 30.

=item * maxlength (optional)

If this is not given, the component tries to come up with some reasonable
value based on the column's type and length.

=back

=cut
</%doc>
<input type="text" name="<% $col_name %>" value="<% $val | h %>" size="<% $size %>" maxlength="<% $maxlength %>" class="<% $class %>">\
<%args>
$row => undef
$column
$class => $m->base_comp->attr_if_exists('text_input_class_default')
$size => $m->base_comp->attr_if_exists('text_input_size_default') || 30
$maxlength => $size
</%args>
<%init>
my $val;

my $col_name = ref $column ? $column->name : $column;

if (defined $row)
{
    $val = $row->select( $col_name );
}

$val = '' unless defined $val;

$maxlength =
    $column->length && $column->length < $maxlength ? $column->length :
    ( ! $column->is_character ? 10 : $maxlength );

if ( $maxlength > $size && exists $ARGS{size} )
{
    $maxlength = $size;
}
elsif ( $maxlength < $size )
{
    $size = $maxlength;
}
</%init>