From 11e4b8f332482c1becab9e099181b7cf44b88b09 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 27 Dec 2010 13:42:44 +0100 Subject: [PATCH] Hilfsfunktionen textarea_tag und radiobutton_tag --- SL/Template/Plugin/L.pm | 53 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 011af9a1f..710f1c923 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -60,7 +60,7 @@ sub html_tag { my $content = shift; my $attributes = $self->attributes(@_); - return "<${tag}${attributes}/>" unless $content; + return "<${tag}${attributes}/>" unless defined($content); return "<${tag}${attributes}>${content}"; } @@ -75,6 +75,18 @@ sub select_tag { return $self->html_tag('select', $options_str, %attributes, name => $name); } +sub textarea_tag { + my $self = shift; + my $name = shift; + my $content = shift; + my %attributes = _hashify(@_); + + $attributes{id} ||= $self->name_to_id($name); + $content = $content ? '' : _H($content); + + return $self->html_tag('textarea', $content, %attributes, name => $name); +} + sub checkbox_tag { my $self = shift; my $name = shift; @@ -96,6 +108,27 @@ sub checkbox_tag { return $code; } +sub radio_button_tag { + my $self = shift; + my $name = shift; + my %attributes = _hashify(@_); + + $attributes{value} = 1 unless defined $attributes{value}; + $attributes{id} ||= $self->name_to_id($name . "_" . $attributes{value}); + my $label = delete $attributes{label}; + + if ($attributes{checked}) { + $attributes{checked} = 'checked'; + } else { + delete $attributes{checked}; + } + + my $code = $self->html_tag('input', undef, %attributes, name => $name, type => 'radio'); + $code .= $self->html_tag('label', $label, for => $attributes{id}) if $label; + + return $code; +} + sub input_tag { my $self = shift; my $name = shift; @@ -243,6 +276,12 @@ Creates a HTML 'input type=text' tag named C<$name> with the value C<$value> and with arbitrary HTML attributes from C<%attributes>. The tag's C defaults to C. +=item C + +Creates a HTML 'textarea' tag named C<$name> with the content +C<$value> and with arbitrary HTML attributes from C<%attributes>. The +tag's C defaults to C. + =item C Creates a HTML 'input type=checkbox' tag named C<$name> with arbitrary @@ -253,8 +292,6 @@ If C<%attributes> contains a key C