From: Moritz Bunkus Date: Mon, 15 Nov 2021 09:09:19 +0000 (+0100) Subject: P.radio_button/checkbox_tag: label_xyz-Attribute als xzy an Label-Tag durchreichen X-Git-Tag: kivitendo-mebil_0.1-0~10^2~2^2~296 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=b6b88a99bfd86c1bd8290d38e24f4fdf0939fa3e;p=kivitendo-erp.git P.radio_button/checkbox_tag: label_xyz-Attribute als xzy an Label-Tag durchreichen Damit ist es möglich, beliebige Attribute auf dem erzeugten Label-Tag zu setzen, z.B. die Klasse oder einen Inline-Style. Beispiel: [% L.checkbox_tag('awesome', value=1, label='This is awesome', label_class="red") %] --- diff --git a/SL/Presenter/Tag.pm b/SL/Presenter/Tag.pm index 032b179b4..25c7d0c2c 100644 --- a/SL/Presenter/Tag.pm +++ b/SL/Presenter/Tag.pm @@ -247,6 +247,9 @@ sub select_tag { sub checkbox_tag { my ($name, %attributes) = @_; + my %label_attributes = map { (substr($_, 6) => $attributes{$_}) } grep { m{^label_} } keys %attributes; + delete @attributes{grep { m{^label_} } keys %attributes}; + _set_id_attribute(\%attributes, $name); $attributes{value} = 1 unless defined $attributes{value}; @@ -263,7 +266,7 @@ sub checkbox_tag { my $code = ''; $code .= hidden_tag($name, 0, %attributes, id => $attributes{id} . '_hidden') if $for_submit; $code .= html_tag('input', undef, %attributes, name => $name, type => 'checkbox'); - $code .= html_tag('label', $label, for => $attributes{id}) if $label; + $code .= html_tag('label', $label, for => $attributes{id}, %label_attributes) if $label; $code .= javascript(qq|\$('#$attributes{id}').checkall('$checkall');|) if $checkall; return $code; @@ -272,6 +275,9 @@ sub checkbox_tag { sub radio_button_tag { my ($name, %attributes) = @_; + my %label_attributes = map { (substr($_, 6) => $attributes{$_}) } grep { m{^label_} } keys %attributes; + delete @attributes{grep { m{^label_} } keys %attributes}; + $attributes{value} = 1 unless exists $attributes{value}; _set_id_attribute(\%attributes, $name, 1); @@ -286,7 +292,7 @@ sub radio_button_tag { } my $code = html_tag('input', undef, %attributes, name => $name, type => 'radio'); - $code .= html_tag('label', $label, for => $attributes{id}) if $label; + $code .= html_tag('label', $label, for => $attributes{id}, %label_attributes) if $label; return $code; } @@ -574,7 +580,10 @@ C. The tag's C defaults to C<1>. If C<%attributes> contains a key C