From: Moritz Bunkus Date: Fri, 8 Jan 2010 13:56:36 +0000 (+0100) Subject: HTML-IDs aus Attributnamen nur mit für IDs gültigen Zeichen bilden X-Git-Tag: release-2.6.2beta1~331^2~25 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=71f55f78545971d867d1e3abe9daaee0f6a1e380;p=kivitendo-erp.git HTML-IDs aus Attributnamen nur mit für IDs gültigen Zeichen bilden --- diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index f044fc165..93de09bb2 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -17,6 +17,16 @@ sub new { return bless { }, $class; } +sub name_to_id { + my $self = shift; + my $name = shift; + + $name =~ s/[^\w_]/_/g; + $name =~ s/_+/_/g; + + return $name; +} + sub attributes { my $self = shift; my $options = shift || {}; @@ -48,7 +58,7 @@ sub select_tag { my $attributes = shift || {}; $attributes->{name} = $name; - $attributes->{id} ||= $name; + $attributes->{id} ||= $self->name_to_id($name); return $self->html_tag('select', $options_str, $attributes); } @@ -106,8 +116,14 @@ functions that create HTML tags from various kinds of data sources. =head1 FUNCTIONS +=head2 LOW-LEVEL FUNCTIONS + =over 4 +=item C + +Converts a name to a HTML id by replacing various characters. + =item C Creates a string from all elements in C<\%items> suitable for usage as @@ -121,6 +137,29 @@ C<$content_string> between the two. If C<$content_string> is undefined or empty then only a Etag/E tag will be created. Attributes are key/value pairs added to the opening tag. +C<$content_string> is not HTML escaped. + +=back + +=head2 HIGH-LEVEL FUNCTIONS + +=over 4 + +=item C + +Creates a HTML 'select' tag named $name with the contents +$options_string and with arbitrary HTML attributes from +C<\%attributes>. The tag's C defaults to C. + +The $options_string is usually created by the C +function. + +=back + +=head2 CONVERSION FUNCTIONS + +=over 4 + =item C Creates a string suitable for a HTML 'select' tag consisting of one @@ -149,15 +188,6 @@ respectively. For cases 3 and 4 C<$options{value}> defaults to C and C<$options{title}> defaults to C<$options{value}>. -=item C - -Creates a HTML 'select' tag named $name with the contents -$options_string and with arbitrary HTML attributes from -C<\%attributes>. The tag's C defaults to C<$name>. - -The $options_string is usually created by the C -function. - =back =head1 MODULE AUTHORS