| 1 |
|
| 2 |
################################################################################### |
| 3 |
# |
| 4 |
# Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de |
| 5 |
# Embperl - Copyright (c) 2008-2014 Gerald Richter |
| 6 |
# |
| 7 |
# You may distribute under the terms of either the GNU General Public |
| 8 |
# License or the Artistic License, as specified in the Perl README file. |
| 9 |
# |
| 10 |
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR |
| 11 |
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 12 |
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
# |
| 14 |
# $Id$ |
| 15 |
# |
| 16 |
################################################################################### |
| 17 |
|
| 18 |
package Embperl::Form::Control::select ; |
| 19 |
|
| 20 |
use strict ; |
| 21 |
use vars qw{%fdat} ; |
| 22 |
use base 'Embperl::Form::ControlMultValue' ; |
| 23 |
|
| 24 |
use Embperl::Inline ; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
1 ; |
| 29 |
|
| 30 |
__EMBPERL__ |
| 31 |
|
| 32 |
[# --------------------------------------------------------------------------- |
| 33 |
# |
| 34 |
# show_hidden - out hidden field |
| 35 |
#] |
| 36 |
|
| 37 |
[$ sub show_hidden ($self, $req) $] |
| 38 |
<input type="hidden" name="[+ $self -> {name} +]"> |
| 39 |
[$endsub$] |
| 40 |
|
| 41 |
[# --------------------------------------------------------------------------- |
| 42 |
# |
| 43 |
# show_control - output the control |
| 44 |
#] |
| 45 |
|
| 46 |
[$ sub show_control ($self, $req, $filter) |
| 47 |
|
| 48 |
my $name = $self -> {name} ; |
| 49 |
$filter ||= $self -> {filter} ; |
| 50 |
my $nsprefix = $self -> form -> {jsnamespace} ; |
| 51 |
my $val ; |
| 52 |
my $i = 0 ; |
| 53 |
my ($values, $options) = $self -> get_all_values ($req) ; |
| 54 |
my ($ctlattrs, $ctlid, $ctlname) = $self -> get_std_control_attr($req) ; |
| 55 |
$values ||= [] ; |
| 56 |
$] |
| 57 |
<select name="[+ $ctlname +]" [+ $self->{multiple}?'multiple':''+] [+ do { local $escmode = 0 ; $ctlattrs } +] |
| 58 |
[$if ($self -> {rows}) $] size="[+ $self->{rows} +]" [$endif$] |
| 59 |
[$if ($self -> {trigger}) $]_ef_attach="ef_select"[$endif$] |
| 60 |
> |
| 61 |
[* $i = 0 ; *] |
| 62 |
[$ foreach $val (@$values) $] |
| 63 |
[$if !defined ($filter) || ($val =~ /$filter/i) $] |
| 64 |
<option value="[+ $val +]">[+ $options ->[$i] || $val +]</option> |
| 65 |
[$endif$] |
| 66 |
[* $i++ ; *] |
| 67 |
[$endforeach$] |
| 68 |
</select> |
| 69 |
[$endsub$] |
| 70 |
|
| 71 |
__END__ |
| 72 |
|
| 73 |
=pod |
| 74 |
|
| 75 |
=head1 NAME |
| 76 |
|
| 77 |
Embperl::Form::Control::select - A select control inside an Embperl Form |
| 78 |
|
| 79 |
|
| 80 |
=head1 SYNOPSIS |
| 81 |
|
| 82 |
{ |
| 83 |
type => 'select', |
| 84 |
text => 'blabla', |
| 85 |
name => 'foo', |
| 86 |
values => [1,2,3], |
| 87 |
options => ['foo', 'bar', 'none'], |
| 88 |
rows => 5 |
| 89 |
} |
| 90 |
|
| 91 |
=head1 DESCRIPTION |
| 92 |
|
| 93 |
Used to create an select control inside an Embperl Form. |
| 94 |
See Embperl::Form on how to specify parameters. |
| 95 |
|
| 96 |
=head2 PARAMETER |
| 97 |
|
| 98 |
=head3 type |
| 99 |
|
| 100 |
Needs to be 'select' |
| 101 |
|
| 102 |
=head3 name |
| 103 |
|
| 104 |
Specifies the name of the select control |
| 105 |
|
| 106 |
=head3 text |
| 107 |
|
| 108 |
Will be used as label for the select control |
| 109 |
|
| 110 |
=head3 values |
| 111 |
|
| 112 |
Gives the values as an array ref of the select control. |
| 113 |
|
| 114 |
=head3 options |
| 115 |
|
| 116 |
Gives the options as an array ref that should be displayed to the user. |
| 117 |
If no options are given, the values from values are used. |
| 118 |
|
| 119 |
=head3 rows |
| 120 |
|
| 121 |
If specified a select box is display with the given number of lines. |
| 122 |
If not specified or undef, a drop down list is shown. |
| 123 |
|
| 124 |
=head3 addtop |
| 125 |
|
| 126 |
Array ref which contains items that should be added at the top |
| 127 |
of the select box. Each item consists of an array ref with two |
| 128 |
entries, the first is the value and the second is the option |
| 129 |
that is displayed on the page. If the second is missing the |
| 130 |
value (first entry)is displayed. Example: |
| 131 |
|
| 132 |
addtop => [ [1 => 'first item'], [2 => 'second item']] |
| 133 |
|
| 134 |
=head3 addbottom |
| 135 |
|
| 136 |
Array ref which contains items that should be added at the bottom |
| 137 |
of the select box. Each item consists of an array ref with two |
| 138 |
entries, the first is the value and the second is the option |
| 139 |
that is displayed on the page. If the second is missing the |
| 140 |
value (first entry)is displayed. Example: |
| 141 |
|
| 142 |
addbottom => [ [9999 => 'last item'], [9999 => 'very last item']] |
| 143 |
|
| 144 |
=head3 filter |
| 145 |
|
| 146 |
If given, only items where the value matches the regex given in |
| 147 |
C<filter> are displayed. |
| 148 |
|
| 149 |
=head3 multiple |
| 150 |
|
| 151 |
If set to true, allows multiple selections. |
| 152 |
|
| 153 |
=head1 Author |
| 154 |
|
| 155 |
G. Richter (richter at embperl dot org) |
| 156 |
|
| 157 |
=head1 See Also |
| 158 |
|
| 159 |
perl(1), Embperl, Embperl::Form |
| 160 |
|
| 161 |
|