| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Quiq::Html::Widget::Hidden - Nicht sichtbares und nicht änderbares Formularelement | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | L<Quiq::Html::Widget> | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Ein Hidden-Widget kommuniziert unter einem Namen einen oder | ||||||||||||||||||||||||||||
| 16 | mehrere Werte. Das Widget ist für den Anwender unsichtbar und | ||||||||||||||||||||||||||||
| 17 | sein Zustand kann von diesem nicht manipuliert werden. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =over 4 | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =item id => $id (Default: undef) | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Id. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =item name => $name (Default: undef) | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | Name. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =item value => $str | \@arr (Default: undef) | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Wert bzw. Liste von Werten. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =item hidden => 1 | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | Widget ist unsichtbar. Diese Eigenschaft gilt für Hidden-Widgets | ||||||||||||||||||||||||||||
| 38 | immer und ist nicht änderbar. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =item ignoreIfNull => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Generiere Leerstring, wenn Wert Null (undef oder Leerstring) ist. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item disabled => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Das Element wird nicht submittet. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item undefIf => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Wenn wahr, liefere C<undef> als Widget-Code. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =back | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head1 EXAMPLES | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | Html::Tag-Objekt instantiieren: | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | $obj = Quiq::Html::Tag->new; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | Keine Information: | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | $html = Quiq::Html::Widget::Hidden->html($h); | ||||||||||||||||||||||||||||
| 63 | --> | ||||||||||||||||||||||||||||
| 64 | Leerstring | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Wert: | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | $html = Quiq::Html::Widget::Hidden->html($h, | ||||||||||||||||||||||||||||
| 69 | name => 'x', | ||||||||||||||||||||||||||||
| 70 | value => 4711, | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | --> | ||||||||||||||||||||||||||||
| 73 | <input type="hidden" name="x" value="4711" />\n | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Liste von Werten: | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | $html = Quiq::Html::Widget::Hidden->html($h, | ||||||||||||||||||||||||||||
| 78 | name => 'x', | ||||||||||||||||||||||||||||
| 79 | value => [4711,4712], | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | --> | ||||||||||||||||||||||||||||
| 82 | <input type="hidden" name="x" value="4711" />\n | ||||||||||||||||||||||||||||
| 83 | <input type="hidden" name="x" value="4712" />\n | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =cut | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | package Quiq::Html::Widget::Hidden; | ||||||||||||||||||||||||||||
| 90 | 9 | ▶ | use base qw/Quiq::Html::Widget/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 9 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 93 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 9 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 METHODS | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head2 Konstruktor | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head3 new() - Konstruktor | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | $e = $class->new(@keyVal); | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 4 | my $class = shift; | |||||||||||||||||||||||||||
| 116 | # @_: @keyVal | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # Defaultwerte | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 4 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||
| 121 | id => undef, | ||||||||||||||||||||||||||||
| 122 | disabled => 0, | ||||||||||||||||||||||||||||
| 123 | hidden => 1, | ||||||||||||||||||||||||||||
| 124 | ignoreIfNull => 0, | ||||||||||||||||||||||||||||
| 125 | name => undef, | ||||||||||||||||||||||||||||
| 126 | undefIf => 0, | ||||||||||||||||||||||||||||
| 127 | value => undef, | ||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Werte Konstruktoraufruf | ||||||||||||||||||||||||||||
| 131 | 4 | $self->set(@_); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 4 | return $self; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head2 Objektmethoden | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head3 html() - Generiere HTML-Code | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | $html = $e->html($h); | ||||||||||||||||||||||||||||
| 145 | $html = $class->html($h,@keyVal); | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 4 | ▶ | sub html { | ||||||||||||||||||||||||||
|
Subroutine
html: called CC=11 SCAR=25.5
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 4 | my $this = shift; | |||||||||||||||||||||||||||
| 153 | 4 | my $h = shift; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 4 | ▶ | my $self = ref $this? $this: $this->new(@_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # Attribute | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 4 | my ($id,$disabled,$ignoreIfNull,$name,$undefIf,$value) = | |||||||||||||||||||||||||||
| 160 | $self->get(qw/id disabled ignoreIfNull name undefIf value/); | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # Wert auf Array abbilden. Wenn ignoreIfNull erfüllt, Leerstring liefern. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 4 | my $arr; | |||||||||||||||||||||||||||
| 165 | 4 | ▶ | if (ref $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 1 | $arr = $value; | |||||||||||||||||||||||||||
| 167 | 1 | ▶ | if ($ignoreIfNull && @$arr == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ignoreIfNull and @$arr == 0
MC/DC0%0/2
$ignoreIfNull and @$arr == 0
$ignoreIfNull
@$arr == 0
Truth table33%1/3
A and B
A= $ignoreIfNullB= @$arr == 0
| |||||||||||||||||||||||||||||
| 168 | 0 | return ''; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | else { | ||||||||||||||||||||||||||||
| 172 | 3 | ▶ | if (!defined($value) || $value eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value or $value eq ""
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||
| 173 | 1 | ▶ | if ($ignoreIfNull) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | return ''; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 1 | $value = ''; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | 3 | $arr = [$value]; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # Generierung | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 4 | ▶ | if ($undefIf) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | return undef; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 4 | ▶ | return '' if !$name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 3 | my $str = ''; | |||||||||||||||||||||||||||
| 190 | 3 | for my $val (@$arr) { | |||||||||||||||||||||||||||
| 191 | 4 | $str .= $h->tag('input', | |||||||||||||||||||||||||||
| 192 | type => 'hidden', | ||||||||||||||||||||||||||||
| 193 | id => $id, | ||||||||||||||||||||||||||||
| 194 | disabled => $disabled, | ||||||||||||||||||||||||||||
| 195 | name => $name, | ||||||||||||||||||||||||||||
| 196 | value => $val, | ||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 3 | return $str; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =head1 VERSION | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 1.240 | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 220 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =cut | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 9 | 1; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # eof | ||||||||||||||||||||||||||||