| 1 | package HTML::FormBuilder::Field; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use 5.008_005; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | our $VERSION = '0.11'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Scalar::Util qw(weaken blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 7 | extends qw(HTML::FormBuilder::Base); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | has data => ( | ||||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||
| 17 | isa => sub { | ||||||||||||||||||||||||||||
| 18 | 97 | ▶ | my $data = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 19 | 97 | ▶ | croak('data should be a hashref') unless ref($data) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | }, | ||||||||||||||||||||||||||||
| 21 | default => sub { | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | {}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | }, | ||||||||||||||||||||||||||||
| 24 | 7 | ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub BUILDARGS { | ||||||||||||||||||||||||||||
| 27 | 97 | ▶ | my ($class, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 97 | ▶ | my %args = (@args % 2) ? %{$args[0]} : @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 97 | my $data = $args{data}; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # normalize: if 'input' is not an array, then make it as an array, so that | ||||||||||||||||||||||||||||
| 33 | # we can process the array directly | ||||||||||||||||||||||||||||
| 34 | 97 | ▶ | if ($data->{input} && ref($data->{input}) ne 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data->{"input"} and ref $data->{"input"} ne "ARRAY"
MC/DC100%2/2
$data->{"input"} and ref $data->{"input"} ne "ARRAY"
$data->{"input"}
ref $data->{"input"} ne "ARRAY"
Truth table100%3/3
A and B
A= $data->{"input"}B= ref $data->{"input"} ne "ARRAY"
| |||||||||||||||||||||||||||||
| 35 | 61 | $data->{input} = [$data->{input}]; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 97 | return \%args; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub build { | ||||||||||||||||||||||||||||
| 42 | 71 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
build: called CC=22 SCAR=31.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 71 | my $env = shift; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 71 | my $data = $self->{data}; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 71 | my $stacked = $env->{stacked}; | |||||||||||||||||||||||||||
| 48 | 71 | my $classes = $self->classes; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 71 | my $div_span = "div"; | |||||||||||||||||||||||||||
| 51 | 71 | my $label_column = $classes->{label_column}; | |||||||||||||||||||||||||||
| 52 | 71 | my $input_column = $classes->{input_column}; | |||||||||||||||||||||||||||
| 53 | 71 | ▶ | $input_column = $data->{override_input_class} if ($data->{override_input_class}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 71 | ▶ | if ($stacked == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $div_span = "span"; | |||||||||||||||||||||||||||
| 57 | 0 | $label_column = ""; | |||||||||||||||||||||||||||
| 58 | 0 | $input_column = ""; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 71 | my $input_fields_html = ''; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 71 | my $stacked_attr = {}; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 71 | ▶ | if ($stacked == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 71 | ▶ | my $class = $data->{'class'} ? " $data->{class}" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 71 | ▶ | if ($data->{'type'} and $data->{'type'} eq 'hidden') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$data->{"type"} and $data->{"type"} eq "hidden"
MC/DC0%0/2
$data->{"type"} and $data->{"type"} eq "hidden"
$data->{"type"}
$data->{"type"} eq "hidden"
Truth table33%1/3
A and B
A= $data->{"type"}B= $data->{"type"} eq "hidden"
| |||||||||||||||||||||||||||||
| 68 | 0 | $stacked_attr->{class} = $class; | |||||||||||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||||||||||
| 70 | 71 | $stacked_attr->{class} = "$classes->{row_padding} $classes->{row} clear$class"; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | #create the field label | ||||||||||||||||||||||||||||
| 75 | 71 | ▶ | if (defined $data->{'label'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 56 | ▶ | my $label_text = $data->{'label'}->{'text'} || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$data->{'label'}{'text'} || ''
MC/DC100%1/1
$data->{'label'}{'text'} || ''
$data->{'label'}{'text'}
Truth table100%2/2
A
A= $data->{'label'}{'text'}
| |||||||||||||||||||||||||||||
| 77 | 56 | undef $data->{'label'}->{'text'}; | |||||||||||||||||||||||||||
| 78 | 56 | ▶ | my $required_mark = delete $data->{label}{required_mark} || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $data->{'label'}{'required_mark'} || 0
MC/DC100%1/1
delete $data->{'label'}{'required_mark'} || 0
delete $data->{'label'}{'required_mark'}
Truth table100%2/2
A
A= delete $data->{'label'}{'required_mark'}
| |||||||||||||||||||||||||||||
| 79 | 56 | my $label_html = $self->_build_element_and_attributes('label', $data->{'label'}, $label_text, {required_mark => $required_mark},); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # add a tooltip explanation if given | ||||||||||||||||||||||||||||
| 82 | 56 | ▶ | if ($data->{'label'}{'tooltip'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # img_url is the url of question mark picture | ||||||||||||||||||||||||||||
| 85 | 1 | my $tooltip = _tooltip($data->{'label'}{'tooltip'}{'desc'}, $data->{'label'}{tooltip}{img_url}); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | $input_fields_html .= qq{<div class="$classes->{extra_tooltip_container}">$label_html$tooltip</div>}; | |||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||
| 89 | 55 | ▶ | my $hide_mobile = $label_text ? "" : $classes->{hide_mobile}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 55 | $input_fields_html .= qq{<$div_span class="$label_column $hide_mobile form_label">$label_html</$div_span>}; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # create the input field | ||||||||||||||||||||||||||||
| 96 | 71 | ▶ | if (defined $data->{'input'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | #if there are more than 1 input field in a single row then we generate 1 by 1 | ||||||||||||||||||||||||||||
| 99 | 61 | my $inputs = $data->{input}; | |||||||||||||||||||||||||||
| 100 | 61 | $input_fields_html .= qq{<$div_span class="$input_column">}; | |||||||||||||||||||||||||||
| 101 | 61 | foreach my $input (@{$inputs}) { | |||||||||||||||||||||||||||
| 102 | 76 | $input_fields_html .= $self->_build_input($input, $env); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 71 | ▶ | if (defined $data->{'comment'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 1 | ▶ | $data->{'comment'}->{'class'} ||= ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$data->{"comment"}{"class"} ||= ""
MC/DC0%0/1
$data->{"comment"}{"class"} ||= ""
$data->{"comment"}{"class"}
Truth table50%1/2
A
A= $data->{"comment"}{"class"}
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | ▶ | unless ($data->{comment}->{no_new_line}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 1 | $input_fields_html .= '<br>'; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 1 | $input_fields_html .= $self->_build_element_and_attributes('p', $data->{'comment'}, $data->{'comment'}->{'text'}); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 71 | ▶ | if (defined $data->{'error'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | my @errors = | ||||||||||||||||||||||||||||
| 118 | ref($data->{'error'}) eq 'ARRAY' | ||||||||||||||||||||||||||||
| 119 | 1 | ? @{$data->{error}} | |||||||||||||||||||||||||||
| 120 | 48 | ▶ | : $data->{error}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 48 | foreach my $error_box (@errors) { | |||||||||||||||||||||||||||
| 123 | 48 | $input_fields_html .= $self->_build_element_and_attributes('p', $error_box, $error_box->{text}); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | #close the input tag | ||||||||||||||||||||||||||||
| 129 | 71 | ▶ | if (defined $data->{'input'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 61 | $input_fields_html .= '</' . $div_span . '>'; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 71 | ▶ | if ($stacked == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 71 | $input_fields_html = $self->_build_element_and_attributes('div', $stacked_attr, $input_fields_html); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 71 | return $input_fields_html; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | ##################################################################### | ||||||||||||||||||||||||||||
| 141 | # Usage : build the input field its own attributes | ||||||||||||||||||||||||||||
| 142 | # Purpose : perform checking build the input field according to its own | ||||||||||||||||||||||||||||
| 143 | # characteristics | ||||||||||||||||||||||||||||
| 144 | # Returns : input field with its attributes in string | ||||||||||||||||||||||||||||
| 145 | # Parameters : $input_field in HASH ref for example | ||||||||||||||||||||||||||||
| 146 | # $attributes = {'id' => 'test', 'name' => 'test', 'class' => 'myclass'} | ||||||||||||||||||||||||||||
| 147 | # Comments : check pod below to understand how to create different input fields | ||||||||||||||||||||||||||||
| 148 | # See Also : | ||||||||||||||||||||||||||||
| 149 | ##################################################################### | ||||||||||||||||||||||||||||
| 150 | sub _build_input { | ||||||||||||||||||||||||||||
| 151 | 76 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_input: called CC=18 SCAR=29.4
| |||||||||||||||||||||||||||||
| 152 | 76 | my $input_field = shift; | |||||||||||||||||||||||||||
| 153 | 76 | my $env = shift; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 76 | my $html = ''; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # delete this so that it doesn't carry on to the next field | ||||||||||||||||||||||||||||
| 158 | # I don't know why should delete it(undef it) | ||||||||||||||||||||||||||||
| 159 | 76 | my $heading = delete $input_field->{'heading'}; | |||||||||||||||||||||||||||
| 160 | 76 | my $trailing = delete $input_field->{'trailing'}; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # wrap <input>, heading & trailing <span> in <div> | ||||||||||||||||||||||||||||
| 163 | 76 | my ($wrap_input, $wrap_heading, $wrap_trailing); | |||||||||||||||||||||||||||
| 164 | 76 | ▶ | if ($input_field->{wrap_in_div_class}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 0 | ($wrap_input, $wrap_heading, $wrap_trailing) = @{$input_field->{wrap_in_div_class}}{'input', 'heading', 'trailing'}; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | #create the filed input | ||||||||||||||||||||||||||||
| 169 | 76 | ▶ | if (eval { $input_field->can('widget_html') }) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 170 | 15 | $html = $input_field->widget_html; | |||||||||||||||||||||||||||
| 171 | ▶ | } elsif ($input_field->{'type'} and $input_field->{'type'} eq 'textarea') { | |||||||||||||||||||||||||||
|
Condition100%3/3
$input_field->{"type"} and $input_field->{"type"} eq "textarea"
MC/DC100%2/2
$input_field->{"type"} and $input_field->{"type"} eq "textarea"
$input_field->{"type"}
$input_field->{"type"} eq "textarea"
Truth table100%3/3
A and B
A= $input_field->{"type"}B= $input_field->{"type"} eq "textarea"
| |||||||||||||||||||||||||||||
| 172 | 7 | undef $input_field->{'type'}; | |||||||||||||||||||||||||||
| 173 | 7 | ▶ | my $textarea_value = $input_field->{'value'} || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$input_field->{'value'} || ''
MC/DC0%0/1
$input_field->{'value'} || ''
$input_field->{'value'}
Truth table50%1/2
A
A= $input_field->{'value'}
| |||||||||||||||||||||||||||||
| 174 | 7 | undef $input_field->{'value'}; | |||||||||||||||||||||||||||
| 175 | 7 | $html = $self->_build_element_and_attributes('textarea', $input_field, $textarea_value); | |||||||||||||||||||||||||||
| 176 | } elsif ($input_field->{'type'}) { | ||||||||||||||||||||||||||||
| 177 | 53 | my $type = $input_field->{'type'}; | |||||||||||||||||||||||||||
| 178 | 53 | ▶ | if ($type =~ /^(?:text|password)$/i) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 179 | 28 | $input_field->{'class'} .= ' text'; | |||||||||||||||||||||||||||
| 180 | } elsif ($type =~ /button|submit/) { | ||||||||||||||||||||||||||||
| 181 | 1 | $input_field->{'class'} .= ' button'; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 53 | ▶ | my $tag = ($type =~ /button|submit/ ? 'button' : 'input'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 53 | $html = $self->_build_element_and_attributes($tag, $input_field); | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 53 | ▶ | if ($type =~ /button|submit/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 1 | $html = qq{<span class="$input_field->{class}">$html</span>}; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | 76 | ▶ | if ($wrap_input) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | $html = qq{<div class="$wrap_input">$html</div>}; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 76 | ▶ | if ($heading) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 3 | my $heading_html = qq{<span id="inputheading">$heading</span>}; | |||||||||||||||||||||||||||
| 198 | 3 | ▶ | if ($wrap_heading) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 0 | $heading_html = qq{<div class="$wrap_heading">$heading_html</div>}; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 3 | ▶ | if ($input_field->{'type'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$input_field->{"type"} and $input_field->{"type"} =~ /radio|checkbox/i
MC/DC50%1/2
$input_field->{"type"} and $input_field->{"type"} =~ /radio|checkbox/i
$input_field->{"type"}
$input_field->{"type"} =~ /radio|checkbox/i
Truth table66%2/3
A and B
A= $input_field->{"type"}B= $input_field->{"type"} =~ /radio|checkbox/i
| |||||||||||||||||||||||||||||
| 203 | && ($input_field->{'type'} =~ /radio|checkbox/i)) | ||||||||||||||||||||||||||||
| 204 | { | ||||||||||||||||||||||||||||
| 205 | 1 | $html .= qq{$heading_html<br />}; | |||||||||||||||||||||||||||
| 206 | } else { | ||||||||||||||||||||||||||||
| 207 | 2 | $html = $heading_html . $html; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 76 | ▶ | if ($trailing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 1 | my $trailing_html = qq{<span class="$self->{classes}{inputtrailing}">$trailing</span>}; | |||||||||||||||||||||||||||
| 213 | 1 | ▶ | if ($wrap_trailing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 0 | $trailing_html = qq{<div class="$wrap_trailing">$trailing_html</div>}; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | 1 | $html .= $trailing_html; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 76 | return $html; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | ##################################################################### | ||||||||||||||||||||||||||||
| 223 | # Usage : _tooltip($content, $url) | ||||||||||||||||||||||||||||
| 224 | # Purpose : create tooltip html code | ||||||||||||||||||||||||||||
| 225 | # Returns : HTML | ||||||||||||||||||||||||||||
| 226 | # Comments : | ||||||||||||||||||||||||||||
| 227 | # See Also : | ||||||||||||||||||||||||||||
| 228 | ##################################################################### | ||||||||||||||||||||||||||||
| 229 | sub _tooltip { | ||||||||||||||||||||||||||||
| 230 | 1 | ▶ | my $content = shift; | ||||||||||||||||||||||||||
|
Subroutine
_tooltip: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 231 | 1 | my $url = shift; | |||||||||||||||||||||||||||
| 232 | 1 | $content =~ s/\'/'/g; # Escape for quoting below | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 1 | return qq{ <a href='#' title='$content' rel='tooltip'><img src="$url" /></a>}; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 7 | 1; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | =head1 NAME | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | HTML::FormBuilder::Field - Field container used by HTML::FormBuilder | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | my $form = HTML::FormBuilder->new(data => {id => 'testform}); | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | my $fieldset = $form->add_fieldset({id => 'fieldset1'}); | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | $fieldset->add_field({input => {type => 'text', value => 'Join'}}); | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | # Text only, without input fields | ||||||||||||||||||||||||||||
| 252 | $fieldset->add_field({ | ||||||||||||||||||||||||||||
| 253 | comment => { | ||||||||||||||||||||||||||||
| 254 | text => 'Please check on checkbox below:', | ||||||||||||||||||||||||||||
| 255 | class => 'grd-grid-12', | ||||||||||||||||||||||||||||
| 256 | # no extra <br/> before <span> for comment | ||||||||||||||||||||||||||||
| 257 | no_new_line => 1, | ||||||||||||||||||||||||||||
| 258 | }, | ||||||||||||||||||||||||||||
| 259 | }); | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | # checkbox & explanation text | ||||||||||||||||||||||||||||
| 262 | $fieldset->add_field({ | ||||||||||||||||||||||||||||
| 263 | input => { | ||||||||||||||||||||||||||||
| 264 | id => 'tnc', | ||||||||||||||||||||||||||||
| 265 | name => 'tnc', | ||||||||||||||||||||||||||||
| 266 | type => 'checkbox', | ||||||||||||||||||||||||||||
| 267 | trailing => 'I have read & agree to all terms & condition.', | ||||||||||||||||||||||||||||
| 268 | # wrap <input> & trailing <span> respectively in <div>, with class: | ||||||||||||||||||||||||||||
| 269 | wrap_in_div_class => { | ||||||||||||||||||||||||||||
| 270 | input => 'grd-grid-1', | ||||||||||||||||||||||||||||
| 271 | trailing => 'grd-grid-11' | ||||||||||||||||||||||||||||
| 272 | }, | ||||||||||||||||||||||||||||
| 273 | }, | ||||||||||||||||||||||||||||
| 274 | error => { | ||||||||||||||||||||||||||||
| 275 | id => 'error_tnc', | ||||||||||||||||||||||||||||
| 276 | class => 'errorfield', | ||||||||||||||||||||||||||||
| 277 | }, | ||||||||||||||||||||||||||||
| 278 | validation => [{ | ||||||||||||||||||||||||||||
| 279 | type => 'checkbox_checked', | ||||||||||||||||||||||||||||
| 280 | err_msg => localize('Please agree in order to proceed.'), | ||||||||||||||||||||||||||||
| 281 | }], | ||||||||||||||||||||||||||||
| 282 | # override div container class for input | ||||||||||||||||||||||||||||
| 283 | override_input_class => 'grd-grid-12', | ||||||||||||||||||||||||||||
| 284 | }); | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | $form->add_field($fieldset_index, {input => {type => 'text', value => 'Join'}}); | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | Chylli L<chylli@binary.com> | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | =head1 CONTRIBUTOR | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | Fayland Lam L<fayland@binary.com> | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | Tee Shuwn Yuan L<shuwnyuan@binary.com> | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | =cut | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||