Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ee61dd2b

Von Moritz Bunkus vor mehr als 14 Jahren hinzugefügt

  • ID ee61dd2b559ab9d6bf741086c86fa9076efba022
  • Vorgänger 07036bf1
  • Nachfolger 0e079eba

Neue Option 'with_empty' für options_for_select.

Sorgt dafür, dass das erste Element ein leeres Element ist.

Unterschiede anzeigen:

SL/Template/Plugin/L.pm
107 107
  my $value_key     = $options{value} || 'id';
108 108
  my $title_key     = $options{title} || $value_key;
109 109

  
110
  my @tags          = ();
110
  my @elements      = ();
111
  push @elements, [ undef, $options{empty_title} || '' ] if $options{with_empty};
112

  
111 113
  if ($collection && (ref $collection eq 'ARRAY')) {
112 114
    foreach my $element (@{ $collection }) {
113 115
      my @result = !ref $element            ? ( $element,               $element               )
......
115 117
                 :  ref $element eq 'HASH'  ? ( $element->{$value_key}, $element->{$title_key} )
116 118
                 :                            ( $element->$value_key,   $element->$title_key   );
117 119

  
118
      my %attributes = ( value => $result[0] );
119
      $attributes{selected} = 'selected' if $options{default} && ($options{default} eq ($result[0] || ''));
120

  
121
      push @tags, $self->html_tag('option', _H($result[1]), %attributes);
120
      push @elements, \@result;
122 121
    }
123 122
  }
124 123

  
125
  return join('', @tags);
124
  my $code = '';
125
  foreach my $result (@elements) {
126
    my %attributes = ( value => $result->[0] );
127
    $attributes{selected} = 'selected' if $options{default} && ($options{default} eq ($result->[0] || ''));
128

  
129
    $code .= $self->html_tag('option', _H($result->[1]), %attributes);
130
  }
131

  
132
  return $code;
126 133
}
127 134

  
128 135
1;
......
240 247
For cases 3 and 4 C<$options{value}> defaults to C<id> and
241 248
C<$options{title}> defaults to C<$options{value}>.
242 249

  
250
If the option C<with_empty> is set then an empty element (value
251
C<undef>) will be used as the first element. The title to display for
252
this element can be set with the option C<empty_title> and defaults to
253
an empty string.
254

  
243 255
=back
244 256

  
245 257
=head1 MODULE AUTHORS

Auch abrufbar als: Unified diff