| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | Quiq::Html::Widget::TextArea - Mehrzeiliges Textfeld | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | L<Quiq::Html::Widget> | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =over 4 | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =item id => $id (Default: undef) | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | Id des Textfelds. | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =item class => $class (Default: undef) | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | CSS Klasse des Textfelds. | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =item disabled => $bool (Default: 0) | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | Widget kann nicht editiert werden. | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =item hidden => $bool (Default: 0) | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | Widget ist (aktuell) unsichtbar. | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =item cols => $n (Default: undef) | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | Sichtbare Breite des Texteingabefeldes in Zeichen. | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | =item autoCols => [$minWidth,$maxWidth] | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | Alternative Angabe zu cols: Bereich, in dem die sichtbare Breite des | ||||||||||||||||||||
| 40 | Texteingabefeldes eingestellt wird, in Abhängigkeit von dessen Inhalt. | ||||||||||||||||||||
| 41 | Hat der Inhalt weniger als $minWidth Kolumnen, wird die Breite auf | ||||||||||||||||||||
| 42 | $minWidth eingestellt. Hat der Inhalt mehr als $maxWidth Kolumnen, wird | ||||||||||||||||||||
| 43 | die Breite auf $maxWidth eingestellt. Ist $maxWidth C<undef>, ist die | ||||||||||||||||||||
| 44 | Breite nicht begrenzt. | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =item name => $name (Default: undef) | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | Name des Feldes. | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =item onKeyUp => $js (Default: undef) | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | JavaScript-Handler. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =item rows => $n (Default: undef) | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | Sichtbare Höhe des Texteingabefeldes in Zeilen. | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =item autoRows => [$minHeight,$maxHeight] | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | Alternative Angabe zu rows: Bereich, in dem die sichtbare Höhe des | ||||||||||||||||||||
| 61 | Texteingabefeldes eingestellt wird, in Abhängigkeit von dessen Inhalt. | ||||||||||||||||||||
| 62 | Hat der Inhalt weniger als $minHeight Zeilen, wird die Höhe auf $minHeight | ||||||||||||||||||||
| 63 | eingestellt. Hat der Inhalt mehr als $maxHeight Zeilen, wird die Höhe auf | ||||||||||||||||||||
| 64 | $maxHeight eingestellt. Ist $maxHeight C<undef>, ist die Höhe nicht | ||||||||||||||||||||
| 65 | begrenzt. | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =item style => $style (Default: undef) | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | CSS Definition (inline). | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =item undefIf => $bool (Default: 0) | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | Wenn wahr, liefere C<undef> als Widget-Code. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =item value => $str (Default: undef) | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | Anfänglicher Wert des Felds. | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =back | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | package Quiq::Html::Widget::TextArea; | ||||||||||||||||||||
| 86 | 1 | ▶ | use base qw/Quiq::Html::Widget/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 1 | ▶ | use v5.10; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 89 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 90 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 1 | our $VERSION = '1.240'; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 1 | ▶ | use Quiq::Html::Tag; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =head1 METHODS | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =head2 Konstruktor | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =head3 new() - Konstruktor | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =head4 Synopsis | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | $e = $class->new(@keyVal); | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 113 | 0 | my $class = shift; | |||||||||||||||||||
| 114 | # @_: @keyVal | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | # Defaultwerte | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | my $self = $class->SUPER::new( | |||||||||||||||||||
| 119 | autoCols => undef, | ||||||||||||||||||||
| 120 | autoRows => undef, | ||||||||||||||||||||
| 121 | class => undef, | ||||||||||||||||||||
| 122 | cols => undef, | ||||||||||||||||||||
| 123 | disabled => 0, | ||||||||||||||||||||
| 124 | hidden => 0, | ||||||||||||||||||||
| 125 | id => undef, | ||||||||||||||||||||
| 126 | name => undef, | ||||||||||||||||||||
| 127 | onKeyUp => undef, | ||||||||||||||||||||
| 128 | rows => undef, | ||||||||||||||||||||
| 129 | style => undef, | ||||||||||||||||||||
| 130 | undefIf => 0, | ||||||||||||||||||||
| 131 | value => undef, | ||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | # Werte Konstruktoraufruf | ||||||||||||||||||||
| 135 | 0 | $self->set(@_); | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 0 | return $self; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head2 Objektmethoden | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =head3 html() - Generiere HTML-Code | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | =head4 Synopsis | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | $html = $e->html; | ||||||||||||||||||||
| 149 | $html = $class->html(@keyVal); | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 0 | ▶ | sub html { | ||||||||||||||||||
|
Subroutine
html: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||
| 156 | 0 | my $this = shift; | |||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | 0 | ▶ | my $self = ref $this? $this: $this->new(@_); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | # Attribute | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 0 | my ($autoCols,$autoRows,$class,$cols,$disabled,$id,$name,$onKeyUp,$rows, | |||||||||||||||||||
| 163 | $style,$undefIf,$value) = $self->get(qw/autoCols autoRows class cols | ||||||||||||||||||||
| 164 | disabled id name onKeyUp rows style undefIf value/); | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | # Generierung | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | 0 | my $h = Quiq::Html::Tag->new; | |||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | 0 | ▶ | if ($undefIf) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | 0 | return undef; | |||||||||||||||||||
| 172 | } | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | # Stelle die Breite bzw. Höhe des Feldes anhand seines Inhalts ein | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | 0 | ▶ | if ($autoCols) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 177 | 0 | my ($minCols,$maxCols) = @$autoCols; | |||||||||||||||||||
| 178 | 0 | my $n = 0; | |||||||||||||||||||
| 179 | 0 | ▶ | if (defined $value) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 180 | 0 | for (split /\n/,$value) { | |||||||||||||||||||
| 181 | 0 | my $l = length; | |||||||||||||||||||
| 182 | 0 | ▶ | if ($l > $n) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 183 | 0 | $n = $l; | |||||||||||||||||||
| 184 | } | ||||||||||||||||||||
| 185 | } | ||||||||||||||||||||
| 186 | } | ||||||||||||||||||||
| 187 | 0 | ▶ | if ($n < $minCols) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 188 | 0 | $cols = $minCols; | |||||||||||||||||||
| 189 | } | ||||||||||||||||||||
| 190 | ▶ | elsif (defined($maxCols) && $n > $maxCols) { | |||||||||||||||||||
|
Condition0%0/3
defined $maxCols and $n > $maxCols
MC/DC0%0/2
defined $maxCols and $n > $maxCols
defined $maxCols
$n > $maxCols
Truth table0%0/3
A and B
A= defined $maxColsB= $n > $maxCols
| |||||||||||||||||||||
| 191 | 0 | $cols = $maxCols; | |||||||||||||||||||
| 192 | } | ||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||
| 194 | 0 | $cols = $n; | |||||||||||||||||||
| 195 | } | ||||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | 0 | ▶ | if ($autoRows) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 199 | 0 | my ($minRows,$maxRows) = @$autoRows; | |||||||||||||||||||
| 200 | 0 | ▶ | my $n = defined $value? $value =~ tr/\n//: 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 201 | 0 | ▶ | if ($n < $minRows) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 202 | 0 | $rows = $minRows; | |||||||||||||||||||
| 203 | } | ||||||||||||||||||||
| 204 | ▶ | elsif (defined($maxRows) && $n > $maxRows) { | |||||||||||||||||||
|
Condition0%0/3
defined $maxRows and $n > $maxRows
MC/DC0%0/2
defined $maxRows and $n > $maxRows
defined $maxRows
$n > $maxRows
Truth table0%0/3
A and B
A= defined $maxRowsB= $n > $maxRows
| |||||||||||||||||||||
| 205 | 0 | $rows = $maxRows; | |||||||||||||||||||
| 206 | } | ||||||||||||||||||||
| 207 | else { | ||||||||||||||||||||
| 208 | 0 | $rows = $n; | |||||||||||||||||||
| 209 | } | ||||||||||||||||||||
| 210 | } | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | 0 | return $h->tag('textarea', | |||||||||||||||||||
| 213 | id => $id, | ||||||||||||||||||||
| 214 | name => $name, | ||||||||||||||||||||
| 215 | class => $class, | ||||||||||||||||||||
| 216 | style => $style, | ||||||||||||||||||||
| 217 | disabled => $disabled, | ||||||||||||||||||||
| 218 | onkeyup => $onKeyUp, | ||||||||||||||||||||
| 219 | cols => $cols, | ||||||||||||||||||||
| 220 | rows => $rows, | ||||||||||||||||||||
| 221 | $value | ||||||||||||||||||||
| 222 | ); | ||||||||||||||||||||
| 223 | } | ||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | =head1 VERSION | ||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | 1.240 | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | =head1 AUTHOR | ||||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | =head1 COPYRIGHT | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | =head1 LICENSE | ||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 242 | it under the same terms as Perl itself. | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | =cut | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | 1 | 1; | |||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | # eof | ||||||||||||||||||||