Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 40ac390b

Von Sven Schöling vor mehr als 3 Jahren hinzugefügt

  • ID 40ac390b4984b892093a7cec642dd40be6c62c7d
  • Vorgänger b5985bcf
  • Nachfolger b77b3b5d

mobile: P.M.input_tag

Unterschiede anzeigen:

SL/Presenter/MaterialComponents.pm
26 26
use constant MEDIUM          => 'medium';
27 27
use constant SMALL           => 'small';
28 28
use constant TINY            => 'tiny';
29
use constant INPUT_FIELD     => 'input-field';
29 30

  
30 31
use constant WAVES_EFFECT    => 'waves-effect';
31 32
use constant WAVES_LIGHT     => 'waves-light';
......
93 94
  @classes;
94 95
}
95 96

  
97
sub _set_id_attribute {
98
  my ($attributes, $name, $unique) = @_;
99

  
100
  if (!delete($attributes->{no_id}) && !$attributes->{id}) {
101
    $attributes->{id}  = name_to_id($name);
102
    $attributes->{id} .= '_' . $attributes->{value} if $unique;
103
  }
104

  
105
  %{ $attributes };
106
}
107

  
108
{ # This will give you an id for identifying html tags and such.
109
  # It's guaranteed to be unique unless you exceed 10 mio calls per request.
110
  # Do not use these id's to store information across requests.
111
my $_id_sequence = int rand 1e7;
112
sub _id {
113
  return ( $_id_sequence = ($_id_sequence + 1) % 1e7 );
114
}
115
}
116

  
117
sub name_to_id {
118
  my ($name) = @_;
119

  
120
  if (!$name) {
121
    return "id_" . _id();
122
  }
123

  
124
  $name =~ s/\[\+?\]/ _id() /ge; # give constructs with [] or [+] unique ids
125
  $name =~ s/[^\w_]/_/g;
126
  $name =~ s/_+/_/g;
127

  
128
  return $name;
129
}
130

  
96 131
sub button_tag {
97 132
  my ($onclick, $value, %attributes) = @_;
98 133

  
......
148 183
sub input_tag {
149 184
  my ($name, $value, %attributes) = @_;
150 185

  
151
  # todo icons
152
  # todo label/active
153
  # todo validate
186
  _set_id_attribute(\%attributes, $attributes{name});
187

  
188
  my $class = delete %attributes{class};
189
  my $icon  = $attributes{icon}
190
    ? icon(delete $attributes{icon}, class => 'prefix')
191
    : '';
192

  
193
  my $label = $attributes{label}
194
    ? html_tag('label', delete $attributes{label}, for => $attributes{id})
195
    : '';
196

  
197
  $attributes{type} //= 'text';
198

  
199
  html_tag('div',
200
    $icon .
201
    html_tag('input', undef, value => $value, %attributes, name => $name) .
202
    $label,
203
    class => [ grep $_, $class, INPUT_FIELD ],
204
  );
205
}
206

  
154 207

  
155
  html_tag('input', $name, $value, %attributes) . html_tag('label', for => $attributes{id}, $name);
156 208
}
157 209

  
158 210

  
templates/mobile_webpages/test/components.html
26 26

  
27 27
<h2>Inputs</h2>
28 28

  
29
[% P.M.input_tag("", "test string") %]
29

  
30
[% P.M.input_tag("", "", label="test input without anything") %]
31
[% P.M.input_tag("", "default value", label="test input with default value") %]
32
[% P.M.input_tag("", "", placeholder="with placeholder", label="test input with placeholder") %]
33
[% P.M.input_tag("", "default value", placeholder="with placeholder", label="test input with placeholder and default value") %]
34

  
35
<h3>With grid:</h3>
36
<div class="row">
37
[% P.M.input_tag("", "", label="2 cols", class="col s6") %]
38
[% P.M.input_tag("", "", label="2 cols", class="col s6") %]
39
[% P.M.input_tag("i1", "", placeholder="2 cols placeholder", icon="phone", class="col s6") %]
40
[% P.M.input_tag("i2", "", label="2 cols label", icon="account_circle", class="col s6") %]
41
</div>

Auch abrufbar als: Unified diff