Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b6b88a99

Von Moritz Bunkus vor etwa 3 Jahren hinzugefügt

  • ID b6b88a99bfd86c1bd8290d38e24f4fdf0939fa3e
  • Vorgänger c48270dd
  • Nachfolger 52d62341

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") %]

Unterschiede anzeigen:

SL/Presenter/Tag.pm
247 247
sub checkbox_tag {
248 248
  my ($name, %attributes) = @_;
249 249

  
250
  my %label_attributes = map { (substr($_, 6) => $attributes{$_}) } grep { m{^label_} } keys %attributes;
251
  delete @attributes{grep { m{^label_} } keys %attributes};
252

  
250 253
  _set_id_attribute(\%attributes, $name);
251 254

  
252 255
  $attributes{value}   = 1 unless defined $attributes{value};
......
263 266
  my $code  = '';
264 267
  $code    .= hidden_tag($name, 0, %attributes, id => $attributes{id} . '_hidden') if $for_submit;
265 268
  $code    .= html_tag('input', undef,  %attributes, name => $name, type => 'checkbox');
266
  $code    .= html_tag('label', $label, for => $attributes{id}) if $label;
269
  $code    .= html_tag('label', $label, for => $attributes{id}, %label_attributes) if $label;
267 270
  $code    .= javascript(qq|\$('#$attributes{id}').checkall('$checkall');|) if $checkall;
268 271

  
269 272
  return $code;
......
272 275
sub radio_button_tag {
273 276
  my ($name, %attributes) = @_;
274 277

  
278
  my %label_attributes = map { (substr($_, 6) => $attributes{$_}) } grep { m{^label_} } keys %attributes;
279
  delete @attributes{grep { m{^label_} } keys %attributes};
280

  
275 281
  $attributes{value}   = 1 unless exists $attributes{value};
276 282

  
277 283
  _set_id_attribute(\%attributes, $name, 1);
......
286 292
  }
287 293

  
288 294
  my $code  = html_tag('input', undef,  %attributes, name => $name, type => 'radio');
289
  $code    .= html_tag('label', $label, for => $attributes{id}) if $label;
295
  $code    .= html_tag('label', $label, for => $attributes{id}, %label_attributes) if $label;
290 296

  
291 297
  return $code;
292 298
}
......
574 580

  
575 581
If C<%attributes> contains a key C<label> then a HTML 'label' tag is
576 582
created with said C<label>. No attribute named C<label> is created in
577
that case.
583
that case. Furthermore, all attributes whose names start with
584
C<label_> become attributes on the label tag without the C<label_>
585
prefix. For example, C<label_style='#ff0000'> will be turned into
586
C<style='#ff0000'> on the label tag, causing the text to become red.
578 587

  
579 588
If C<%attributes> contains a key C<checkall> then the value is taken as a
580 589
JQuery selector and clicking this checkbox will also toggle all checkboxes
......
588 597

  
589 598
If C<%attributes> contains a key C<label> then a HTML 'label' tag is
590 599
created with said C<label>. No attribute named C<label> is created in
591
that case.
600
that case. Furthermore, all attributes whose names start with
601
C<label_> become attributes on the label tag without the C<label_>
602
prefix. For example, C<label_style='#ff0000'> will be turned into
603
C<style='#ff0000'> on the label tag, causing the text to become red.
592 604

  
593 605
=item C<select_tag $name, \@collection, %attributes>
594 606

  

Auch abrufbar als: Unified diff