blib/lib/HTML/Object/DOM/Element/Input.pm untested

filter: Statementstmt 0.0% 0 / 179 Branchbran 0.0% 0 / 96 Conditioncond 0.0% 0 / 98 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 403 CC 49 SCAR 74.3
CC
49
Cov
0%
_set_up_down
2352.0
init
6.0
BEGIN
2.0
CRAP 1685.7
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Input.pm
3 ## Version v0.2.2
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/23
7 ## Modified 2023/11/06
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTML::Object::DOM::Element::Input;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( HTML::Object::DOM::Element );
21 use vars qw( $VERSION );
22 use HTML::Object::DOM::Element::Shared qw( :input );
23 use POSIX ();
24 our $VERSION = 'v0.2.2';
25 };
26  
27 use strict;
28 use warnings;
29  
30 sub init
31 {
32 my $self = shift( @_ );
33 $self->{_init_strict_use_sub} = 1;
34 $self->SUPER::init( @_ ) || return( $self->pass_error );
35 $self->{tag} = 'input' if( !CORE::length( "$self->{tag}" ) );
36 return( $self );
37 }
38  
39 # Note: property accept is inherited
40  
41 # Note: property accessKey is inherited
42  
43 # Note: deprecated property align is inherited
44  
45 # Note: property allowdirs is inherited
46  
47 # Note: property alt is inherited
48  
49 # Note: property autocapitalize is inherited
50  
51 # Note: property autocomplete is inherited
52  
53 # Note: property autofocus is inherited
54  
55 # Note: property checked is inherited
56  
57 # Note: property defaultChecked is inherited
58  
59 # Note: property defaultValue is inherited
60  
61 # Note: property dirName is inherited
62  
63 # Note: property disabled is inherited
64  
65 # Note: property files is inherited
66  
67 # Note: property form read-only is inherited
68  
69 # Note: property formAction is inherited
70  
71 # Note: property formEnctype is inherited
72  
73 # Note: property formMethod is inherited
74  
75 # Note: property formNoValidate is inherited
76  
77 # Note: property formTarget is inherited
78  
79 # Note: property height is inherited
80  
81 # Note: property indeterminate is inherited
82  
83 # Note: property inputmode is inherited
84  
85 # Note: property labels read-only is inherited
86  
87 # Note: property list read-only is inherited
88  
89 # Note: property max is inherited
90  
91 # Note: property maxLength is inherited
92  
93 # Note: property min is inherited
94  
95 # Note: property minLength is inherited
96  
97 sub mozGetFileNameArray { return; }
98  
99 sub mozSetFileArray { return; }
100  
101 # Note: property multiple is inherited
102  
103 # Note: property name is inherited
104  
105 sub oninput : lvalue { return( shift->on( 'input', @_ ) ); }
106  
107 sub oninvalid : lvalue { return( shift->on( 'invalid', @_ ) ); }
108  
109 sub onsearch : lvalue { return( shift->on( 'search', @_ ) ); }
110  
111 sub onselectionchange : lvalue { return( shift->on( 'selectionchange', @_ ) ); }
112  
113 # Note: property pattern is inherited
114  
115 # Note: property placeholder is inherited
116  
117 # Note: property readOnly is inherited
118  
119 # Note: property required is inherited
120  
121 # Note: property selectionDirection is inherited
122  
123 # Note: property selectionEnd is inherited
124  
125 # Note: property selectionStart is inherited
126  
127 # Note: property size is inherited
128  
129 # Note: property src is inherited
130  
131 # Note: property step is inherited
132  
133 sub stepDown { return( shift->_set_up_down( { direction => 'down' }, @_ ) ); }
134  
135 sub stepUp { return( shift->_set_up_down( { direction => 'up' }, @_ ) ); }
136  
137 # Note: property type is inherited
138  
139 # Note: deprecated property useMap is inherited
140  
141 # Note: property validationMessage read-only is inherited
142  
143 # Note: property validity read-only is inherited
144  
145 # Note: property value is inherited
146  
147 # Note: property valueAsDate is inherited
148  
149 # Note: property valueAsNumber is inherited
150  
151 # Note: property webkitEntries is inherited
152  
153 # Note: property webkitdirectory is inherited
154  
155 # Note: property width is inherited
156  
157 # Note: property willValidate read-only is inherited
158  
159 # date 1 (day) <input type="date" min="2019-12-25" step="1" />
160 # month 1 (month) <input type="month" min="2019-12" step="12" />
161 # week 1 (week) <input type="week" min="2019-W23" step="2" />
162 # time 60 (seconds) <input type="time" min="09:00" step="900" />
163 # datetime-local 1 (day) <input type="datetime-local" min="2019-12-25T19:30" step="7" />
164 # number 1 <input type="number" min="0" step="0.1" max="10" />
165 # range 1 <input type="range" min="0" step="2" max="10" />
166 #
167 # HTML::Object::InvalidStateError
168 sub _set_up_down
169 {
170 my $self = shift( @_ );
171 my $opts = shift( @_ );
172 my $incr = shift( @_ );
173 $incr = 1 if( !defined( $incr ) || !CORE::length( "$incr" ) );
174 return( $self->error( "First argument must be an hash reference of parameters." ) ) if( ref( $opts ) ne 'HASH' );
175 return( $self->error({
176 message => "Incremental value provided ($incr) is not a valid number.",
177 class => 'HTML::Object::SyntaxError',
178 }) ) if( !$self->_is_number( $incr ) );
179 # "If the value is a float, the value will increment as if Math.floor(stepDecrement) was passed. If the value is negative, the value will be incremented instead of decremented. "
180 # <https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/stepDown>
181 $incr = POSIX::floor( "$incr" );
182 my $dir = $opts->{direction} // 'down';
183 my $val = $self->value;
184 $self->_load_class( 'DateTime' ) || return( $self->pass_error );
185 $self->_load_class( 'DateTime::Format::Strptime' ) || return( $self->pass_error );
186 $self->_load_class( 'DateTime::Duration' ) || return( $self->pass_error );
187 my $type2unit =
188 {
189 date => { unit => 'day', pattern => '%Y-%m-%d', default => '1970-01-01', step_re => qr/^\d+$/ },
190 month => { unit => 'month', pattern => '%Y-%m', default => '1970-01', step_re => qr/^\d+$/ },
191 week => { unit => 'week', pattern => '%Y-W%W', default => '1970-W1', step_re => qr/^\d+$/ },
192 'time' => { unit => 'second', pattern => ['%H:%M:%S','%H:%M'], default => '00:00:00', step_re => qr/^\d+$/, dt_format => '%02d:%02d', format => '%H:%M:%S' },
193 'datetime-local' => { unit => 'second', pattern => ['%Y-%m-%dT%H:%M:%S','%Y-%m-%dT%H:%M','%Y-%m-%dT%H'], default => '1970-01-01T00:00', step_re => qr/^\d+$/, format => '%Y-%m-%dT%H:%M:%S' },
194 number => { unit => 1, default => 0, step_re => qr/^\d+(?:\.\d+)?$/ },
195 range => { unit => 1, default => 0, step_re => qr/^\d+(?:\.\d+)?$/ },
196 };
197 my $type = $self->attr( 'type' ) || return( $self->error({
198 message => "This input type has no type attribute.",
199 class => 'HTML::Object::SyntaxError',
200 }) );
201 my $def = $type2unit->{ $type } || return( $self->error({
202 message => "This input type \"$type\" is unsupported for " . ( $dir eq 'up' ? 'stepUp' : 'stepDown' ),
203 class => 'HTML::Object::InvalidStateError',
204 }) );
205 my $min = $self->attr( 'min' );
206 my $max = $self->attr( 'max' );
207 my $step = $self->attr( 'step' );
208 $step = 1 if( !defined( $step ) );
209 $step = $step + 0;
210 $step = 1 if( !CORE::length( $step ) || lc( $step ) eq 'any' || $step !~ /$def->{step_re}/ );
211 return( $self->error({
212 message => "This input step value provided '" . ( $step // 'undef' ) . "' (" . $self->_str_val( $step // 'undef' ) . ") is not a proper number.",
213 class => 'HTML::Object::SyntaxError',
214 }) ) if( !$self->_is_number( $step ) );
215
216 my $parse;
217 $parse = sub
218 {
219 my $this = shift( @_ );
220 return( $this ) if( $type eq 'week' || $type eq 'number' || $type eq 'range' );
221 my( $fmt, $dt );
222 if( ref( $def->{pattern} ) eq 'ARRAY' )
223 {
224 foreach my $pat ( @{$def->{pattern}} )
225 {
226 $fmt = DateTime::Format::Strptime->new( pattern => $pat );
227 $dt = $fmt->parse_datetime( "$this" );
228 last if( $dt );
229 }
230 }
231 else
232 {
233 $fmt = DateTime::Format::Strptime->new( pattern => $def->{pattern} );
234 $dt = $fmt->parse_datetime( "$this" );
235 }
236 if( !defined( $dt ) )
237 {
238 return( $self->error({
239 message => "Unable to parse $type value \"$this\"': " . $fmt->errmsg,
240 class => 'HTML::Object::InvalidStateError',
241 }) );
242 }
243
244 if( $def->{format} )
245 {
246 $dt->set_formatter( DateTime::Format::Strptime->new( pattern => $def->{format} ) );
247 }
248 else
249 {
250 $dt->set_formatter( $fmt );
251 }
252 return( $dt );
253 };
254
255 $max //= '';
256 if( !defined( $val ) || !CORE::length( "$val" ) )
257 {
258 # If min is provided and we are told to go up, min is our starting value and we return immediately.
259 # However, the reverse is not true, i.e. if we go down and max is defined, we do not start at max value. We would start at 00:00
260 if( $dir eq 'up' && defined( $min ) && CORE::length( "$min" ) )
261 {
262 if( exists( $type2unit->{ $type } ) )
263 {
264 my $this = $parse->( $min );
265 # return( $self->error({
266 # message => "Unable to parse $type minimum value \"$min\"': " . $fmt->errmsg,
267 # class => 'HTML::Object::InvalidStateError',
268 # }) ) if( !defined( $this ) );
269 return( $self->pass_error ) if( !defined( $this ) );
270 $min = $this;
271 }
272 # $self->value = $min;
273 $self->value( $min );
274 return( $self );
275 }
276 elsif( $dir eq 'down' && defined( $max ) && CORE::length( "$max" ) )
277 {
278 if( exists( $type2unit->{ $type } ) )
279 {
280 my $this = $parse->( $max );
281 # return( $self->error({
282 # message => "Unable to parse $type maximum value \"$max\"': " . $fmt->errmsg,
283 # class => 'HTML::Object::InvalidStateError',
284 # }) ) if( !defined( $this ) );
285 return( $self->pass_error ) if( !defined( $this ) );
286 $max = $this;
287 }
288 # $self->value = $max;
289 $self->value( $max );
290 return( $self );
291 }
292 else
293 {
294 $val = $def->{default};
295 }
296 }
297
298 # try-catch
299 my $rv = eval
300 {
301 my $new;
302 if( $type eq 'number' || $type eq 'range' )
303 {
304 $new = ( $dir eq 'up' )
305 ? ( $val + ( $step * $incr ) )
306 : ( $val - ( $step * $incr ) );
307 if( ( defined( $max ) && CORE::length( "$max" ) && $dir eq 'up' && $new > $max ) ||
308 ( defined( $min ) && CORE::length( "$min" ) && $dir eq 'down' && $new < $min ) )
309 {
310 return( $self );
311 }
312 }
313 # We manage it ourself, i.e. without using DateTime::Format::Strptime, beecause
314 # the parser does not seem capable of recognising format like 2021-W23 even with
315 # the proper pattern
316 elsif( $type eq 'week' )
317 {
318 if( $val =~ /^(\d{1,})-W(\d{1,2})$/ )
319 {
320 my( $y, $w ) = ( $1, $2 );
321 return( $self->error({
322 message => "Week number found \"$w\" is higher than the maximum possible 52",
323 class => 'HTML::Object::InvalidStateError',
324 }) ) if( int( $w ) > 52 );
325 return( $self->error({
326 message => "Week number found \"$w\" is lower than the minimum possible 1",
327 class => 'HTML::Object::InvalidStateError',
328 }) ) if( int( $w ) < 1 );
329 my $dt = DateTime->from_day_of_year( year => $y, day_of_year => ( $w * 7 ) );
330 my $fmt = DateTime::Format::Strptime->new( pattern => $def->{pattern} );
331 $dt->set_formatter( $fmt );
332
333 if( $dir eq 'up' )
334 {
335 $dt->add( weeks => ( $step * $incr ) );
336 }
337 else
338 {
339 $dt->subtract( weeks => ( $step * $incr ) );
340 }
341
342 if( $dir eq 'down' && defined( $min ) && CORE::length( "$min" ) )
343 {
344 my( $min_year, $min_week );
345 if( $min =~ /^(\d{1,})-W(\d{1,2})$/ )
346 {
347 ( $min_year, $min_week ) = ( $1, $2 );
348 return( $self->error({
349 message => "Minimum week number found \"$min_week\" is higher than the maximum possible 52",
350 class => 'HTML::Object::InvalidStateError',
351 }) ) if( int( $min_week ) > 52 );
352 return( $self->error({
353 message => "Minimum week number found \"$min_week\" is lower than the minimum possible 1",
354 class => 'HTML::Object::InvalidStateError',
355 }) ) if( int( $min_week ) < 1 );
356 my $dt_min = DateTime->from_day_of_year( year => $min_year, day_of_year => ( $min_week * 7 ) );
357 $dt_min->set_formatter( $fmt );
358 if( $dt < $dt_min )
359 {
360 # Silently refuse to comply, as browsers do
361 return( $self );
362 }
363 }
364 else
365 {
366 return( $self->error({
367 message => "Unable to parse $type minimum value \"$min\"': unsupported format. It should be 2021-W20 for example.",
368 class => 'HTML::Object::InvalidStateError',
369 }) );
370 }
371 }
372 elsif( $dir eq 'up' && defined( $max ) && CORE::length( "$max" ) )
373 {
374 my( $max_year, $max_week );
375 if( $max =~ /^(\d{1,})-W(\d{1,2})$/ )
376 {
377 ( $max_year, $max_week ) = ( $1, $2 );
378 return( $self->error({
379 message => "Maximum week number found \"$max_week\" is higher than the maximum possible 52",
380 class => 'HTML::Object::InvalidStateError',
381 }) ) if( int( $max_week ) > 52 );
382 return( $self->error({
383 message => "Maximum week number found \"$max_week\" is lower than the minimum possible 1",
384 class => 'HTML::Object::InvalidStateError',
385 }) ) if( int( $max_week ) < 1 );
386 my $dt_max = DateTime->from_day_of_year( year => $max_year, day_of_year => ( $max_week * 7 ) );
387 $dt_max->set_formatter( $fmt );
388 if( $dt > $dt_max )
389 {
390 # Silently refuse to comply, as browsers do
391 return( $self );
392 }
393 }
394 else
395 {
396 return( $self->error({
397 message => "Unable to parse $type maximum value \"$max\"': unsupported format. It should be 2021-W20 for example.",
398 class => 'HTML::Object::InvalidStateError',
399 }) );
400 }
401 }
402 $new = "$dt";
403 }
404 else
405 {
406 return( $self->error({
407 message => "Unable to parse $type value \"$val\"': unsupported format. It should be 2021-W20 for example.",
408 class => 'HTML::Object::InvalidStateError',
409 }) );
410 }
411 }
412 else
413 {
414 my $dt = $parse->( $val );
415 return( $self->pass_error ) if( !defined( $dt ) );
416 # We can pass negative number to duration
417 my $interval = DateTime::Duration->new( "$def->{unit}s" => ( $step * $incr ) );
418 if( $dir eq 'up' )
419 {
420 $dt->add_duration( $interval );
421 }
422 else
423 {
424 $dt->subtract_duration( $interval );
425 }
426
427
428 if( $dir eq 'down' && defined( $min ) && CORE::length( "$min" ) )
429 {
430 my $dt_min = $parse->( "$min" );
431 if( !defined( $dt_min ) )
432 {
433 # return( $self->error({
434 # message => "Unable to parse $type minimum value \"$min\"': " . $fmt->errmsg,
435 # class => 'HTML::Object::InvalidStateError',
436 # }) );
437 return( $self->pass_error );
438 }
439 # $dt_min->set_formatter( $fmt );
440 if( $dt < $dt_min )
441 {
442 # Silently refuse to comply, as browsers do
443 return( $self );
444 }
445 }
446 elsif( $dir eq 'up' && defined( $max ) && CORE::length( "$max" ) )
447 {
448 my $dt_max = $parse->( "$max" );
449 if( !defined( $dt_max ) )
450 {
451 # return( $self->error({
452 # message => "Unable to parse $type maximum value \"$max\"': " . $fmt->errmsg,
453 # class => 'HTML::Object::InvalidStateError',
454 # }) );
455 return( $self->pass_error );
456 }
457 # $dt_max->set_formatter( $fmt );
458 if( $dt > $dt_max )
459 {
460 # Silently refuse to comply, as browsers do
461 return( $self );
462 }
463 }
464 $new = "$dt";
465 }
466 # $self->value = $new;
467 $self->value( $new );
468 return( $self );
469 };
470 if( $@ )
471 {
472 return( $self->error({
473 message => "Error " . ( $opts->{direction} ? 'increasing' : 'decreasing' ) . " the input value: $@",
474 class => 'HTML::Object::InvalidStateError',
475 }) );
476 }
477 return( $rv );
478 }
479  
480 1;
481 # NOTE: POD
482 __END__
483  
484 =encoding utf-8
485  
486 =head1 NAME
487  
488 HTML::Object::DOM::Element::Input - HTML Object DOM Input Class
489  
490 =head1 SYNOPSIS
491  
492 use HTML::Object::DOM::Element::Input;
493 my $input = HTML::Object::DOM::Element::Input->new ||
494 die( HTML::Object::DOM::Element::Input->error, "\n" );
495  
496 =head1 VERSION
497  
498 v0.2.2
499  
500 =head1 DESCRIPTION
501  
502 This interface provides special properties and methods for manipulating the options, layout, and presentation of <input> elements.
503  
504 =head1 INHERITANCE
505  
506 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
507 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Input |
508 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
509  
510 =head1 PROPERTIES
511  
512 Inherits properties from its parent L<HTML::Object::DOM::Element> and the properties exported by L<HTML::Object::DOM::Element::Shared>
513  
514 =head2 accept
515  
516 This returns or sets the element's accept HTML attribute, containing comma-separated list of file types accepted by the server when type is file.
517  
518 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept>
519  
520 =head2 accessKey
521  
522 This returns a string containing a single character that switches input focus to the control when pressed.
523  
524 Example:
525  
526 <button accesskey="s">Some button</button>
527  
528 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/accessKey>, L<accessKey attribute documentation|https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey>
529  
530 =head2 allowdirs
531  
532 This sets or gets a boolean value. This is part of the non-standard Directory Upload API; indicates whether or not to allow directories and files both to be selected in the file list. Implemented only in Firefox and is hidden behind a preference.
533  
534 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#instance_properties_that_apply_only_to_elements_of_type_file>
535  
536 =head2 alt
537  
538 This returns or sets the element's alt attribute, containing alternative text to use when type is image.
539  
540 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#instance_properties_that_apply_only_to_elements_of_type_image>
541  
542 =head2 autocapitalize
543  
544 This defines the capitalization behavior for user input. Valid values are none, off, characters, words, or sentences.
545  
546 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#instance_properties>
547  
548 =head2 autocomplete
549  
550 This returns or sets the element's autocomplete attribute, indicating whether the value of the control can be automatically completed by the browser. Ignored if the value of the type attribute is C<hidden>, C<checkbox>, C<radio>, C<file>, or a button type (C<button>, C<submit>, C<reset>, C<image>). Possible values are:
551  
552 =over 4
553  
554 =item on
555  
556 The browser can autocomplete the value using previously stored value
557  
558 =item off
559  
560 The user must explicitly enter a value
561  
562 =back
563  
564 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/autocomplete>
565  
566 =head2 autofocus
567  
568 This returns or sets the element's autofocus attribute, which specifies that a form control should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form element in a document can have the autofocus attribute. It cannot be applied if the type attribute is set to hidden (that is, you cannot automatically set focus to a hidden control).
569  
570 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/autofocus>
571  
572 =head2 checked
573  
574 This returns a boolean value, which represents the current state of the element when type is checkbox or radio.
575  
576 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checked>
577  
578 =head2 defaultChecked
579  
580 This returns or sets a boolean value, which represents the default state of a radio button or checkbox as originally specified in HTML that
581 created this object.
582  
583 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/defaultChecked>
584  
585 =head2 defaultValue
586  
587 This returns or sets the default value as originally specified in the HTML that created this object.
588  
589 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/defaultValue>
590  
591 =head2 dirName
592  
593 This returns or sets a string, which represents the directionality of the element.
594  
595 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/dirName>
596  
597 =head2 disabled
598  
599 This returns or sets a boolean value, which represents the element's disabled attribute, indicating that the control is not available for interaction. The input values will not be submitted with the form. See also readonly.
600  
601 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/disabled>
602  
603 =head2 files
604  
605 This returns or accepts a L<FileList|HTML::Object::DOM::FileList> object, which contains a list of File objects representing the files selected for upload. However, this being a perl framework, you would have to set the object values yourself.
606  
607 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/files>
608  
609 =head2 form
610  
611 Read-only.
612  
613 L<HTML::Object::DOM::Element::Form> object: this returns a reference to the parent <form> element.
614  
615 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/form>
616  
617 =head2 formAction
618  
619 This returns or sets the element's formaction attribute, containing the C<URI> of a program that processes information submitted by the element. This overrides the action attribute of the parent form.
620  
621 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/formAction>
622  
623 =head2 formEnctype
624  
625 This returns or sets the element's formenctype attribute, containing the type of content that is used to submit the form to the server. This overrides the enctype attribute of the parent form.
626  
627 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/formEnctype>
628  
629 =head2 formMethod
630  
631 This returns or Sets the element's formmethod attribute, containing the HTTP method that the browser uses to submit the form. This overrides the method attribute of the parent form.
632  
633 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/formMethod>
634  
635 =head2 formNoValidate
636  
637 This returns or sets a boolean value, which represents the element's C<formnovalidate> HTML attribute, indicating that the form is not to be validated when it is submitted. This overrides the C<novalidate> attribute of the parent form.
638  
639 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/formNoValidate>
640  
641 =head2 formTarget
642  
643 This returns or sets the element's formtarget attribute, containing a name or keyword indicating where to display the response that is received after submitting the form. This overrides the target attribute of the parent form.
644  
645 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/formTarget>
646  
647 =head2 height
648  
649 This returns or sets the element's height attribute, which defines the height of the image displayed for the button, if the value of type is image.
650  
651 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/height>
652  
653 =head2 indeterminate
654  
655 This returns a boolean value, which represents whether the checkbox or radio button is in indeterminate state. For checkboxes, the effect is that the appearance of the checkbox is obscured/greyed in some way as to indicate its state is indeterminate (not checked but not unchecked). Does not affect the value of the checked attribute, and clicking the checkbox will set the value to false.
656  
657 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/indeterminate>
658  
659 =head2 inputmode
660  
661 This provides a hint to browsers as to the type of virtual keyboard configuration to use when editing this element or its contents.
662  
663 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/inputmode>
664  
665 =head2 labels
666  
667 Read-only.
668  
669 This returns an L<array object|Module::Generic::Array> of C<label> elements that are labels for this element.
670  
671 Example:
672  
673 <label id="label1" for="test">Label 1</label>
674 <input id="test" />
675 <label id="label2" for="test">Label 2</label>
676  
677 window->addEventListener( DOMContentLoaded => sub
678 {
679 my $input = $doc->getElementById( 'test' );
680 for( my $i = 0; $i < $input->labels->length; $i++ )
681 {
682 say( $input->labels->[$i]->textContent ); # "Label 1" and "Label 2"
683 }
684 });
685  
686 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/labels>
687  
688 =head2 list
689  
690 Read-only.
691  
692 This returns the L<element|HTML::Object::DOM::Element> pointed by the list attribute. The property may be C<undef> if no HTML element found in the same tree.
693  
694 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/list>
695  
696 =head2 max
697  
698 This returns or sets a string, which represents the element's max attribute, containing the maximum (numeric or date-time) value for this item, which must not be less than its minimum (min attribute) value.
699  
700 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/max>
701  
702 =head2 maxLength
703  
704 This returns or sets a long, which represents the element's C<maxlength> attribute, containing the maximum number of characters (in Unicode code points) that the value can have. (If you set this to a negative number, an exception will be thrown.)
705  
706 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/maxLength>
707  
708 =head2 min
709  
710 This returns or sets a string, which represents the element's min attribute, containing the minimum (numeric or date-time) value for this item, which must not be greater than its maximum (max attribute) value.
711  
712 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/min>
713  
714 =head2 minLength
715  
716 This returns or sets a long, which represents the element's C<minlength> attribute, containing the minimum number of characters (in Unicode code points) that the value can have. (If you set this to a negative number, an exception will be thrown.)
717  
718 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/minLength>
719  
720 =head2 multiple
721  
722 This returns or sets a boolean value, which represents the element's multiple attribute, indicating whether more than one value is possible (e.g., multiple files).
723  
724 Example:
725  
726 # $fileInput is a <input type=$file multiple>
727 my $fileInput = $doc->getElementById('myfileinput');
728  
729 # If true
730 if( $fileInput->multiple )
731 {
732 for( my $i = 0; $i < $fileInput->files->length; $i++ )
733 {
734 # Loop $fileInput->files
735 }
736 }
737 # Only one $file available
738 else
739 {
740 my $file = $fileInput->files->item(0);
741 }
742  
743 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/multiple>
744  
745 =head2 name
746  
747 This returns or sets a string, which represents the element's name attribute, containing a name that identifies the element when submitting the form.
748  
749 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/name>
750  
751 =head2 pattern
752  
753 This returns or sets a string, which represents the element's pattern attribute, containing a regular expression that the control's value is checked against. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is C<text>, C<search>, C<tel>, C<url> or C<email>; otherwise it is ignored.
754  
755 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/pattern>
756  
757 =head2 placeholder
758  
759 This returns or sets a string, which represents the element's placeholder attribute, containing a hint to the user of what can be entered in the control. The placeholder text must not contain carriage returns or line-feeds. This attribute applies when the value of the type attribute is C<text>, C<search>, C<tel>, C<url> or C<email>; otherwise it is ignored.
760  
761 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/placeholder>
762  
763 =head2 readOnly
764  
765 This returns or sets a boolean value, which represents the element's readonly HTML attribute, indicating that the user cannot modify the value of the control.This is ignored if the value of the type attribute is hidden, range, color, checkbox, radio, file, or a button type.
766  
767 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/readOnly>
768  
769 =head2 required
770  
771 This returns or sets a boolean value, which represents the element's required attribute, indicating that the user must fill in a value before submitting a form.
772  
773 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/required>
774  
775 =head2 selectionDirection
776  
777 This returns or sets a string, which represents the direction in which selection occurred. Possible values are:forward if selection was performed in the start-to-end direction of the current localebackward for the opposite directionnone if the direction is unknown
778  
779 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/selectionDirection>
780  
781 =head2 selectionEnd
782  
783 This returns or sets an unsigned long, which represents the end index of the selected text. When there's no selection, this returns the offset of the character immediately following the current text input cursor position.
784  
785 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/selectionEnd>
786  
787 =head2 selectionStart
788  
789 This returns or sets an unsigned long, which represents the beginning index of the selected text. When nothing is selected, this returns the position of the text input cursor (caret) inside of the C<input> element.
790  
791 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/selectionStart>
792  
793 =head2 size
794  
795 This returns or sets an unsigned long, which represents the element's size attribute, containing visual size of the control. This value is in pixels unless the value of type is text or password, in which case, it is an integer number of characters. Applies only when type is set to C<text>, C<search>, C<tel>, C<url>, C<email>, or C<password>; otherwise it is ignored.
796  
797 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/size>
798  
799 =head2 src
800  
801 This returns or sets a string, which represents the element's src attribute, which specifies a C<URI> for the location of an image to display on the graphical submit button, if the value of type is image; otherwise it is ignored.
802  
803 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/src>
804  
805 =head2 step
806  
807 This returns or sets a string, which represents the element's step attribute, which works with min and max to limit the increments at which a numeric or date-time value can be set. It can be the string any or a positive floating point number. If this is not set to any, the control accepts only values at multiples of the step value greater than the minimum.
808  
809 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/step>, L<documentation on step attribute|https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/step>
810  
811 =head2 type
812  
813 This returns or sets a string, which represents the element's type attribute, indicating the type of control to display. See type attribute of <input> for possible values.
814  
815 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/type>
816  
817 =head2 validationMessage
818  
819 Read-only.
820  
821 This returns or sets a string, which represents a localised message that describes the validation constraints that the control does not satisfy (if any). This is the empty string if the control is not a candidate for constraint validation (willvalidate is false), or it satisfies its constraints. This value can also be set by the L</setCustomValidity> method.
822  
823 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/validationMessage>
824  
825 =head2 validity
826  
827 Read-only.
828  
829 This returns or sets the element's current L<validity state object|HTML::Object::DOM::ValidityState>.
830  
831 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/validity>
832  
833 =head2 value
834  
835 This returns or sets a string, which represents the current value of the control.
836  
837 Note: If the user enters a value different from the value expected, this may return an empty string.
838  
839 This interface does not enforce proper value, so it is up to you to use the right one. For example, using a value of C<2021-W55> for an input of type C<week> is normally illegal since the week number value should be a number between 1 and 53.
840  
841 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/value>
842  
843 =head2 valueAsDate
844  
845 This returns or sets a date, which represents the value of the element, interpreted as a date, or C<undef> if conversion is not possible.
846  
847 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/valueAsDate>
848  
849 =head2 valueAsNumber
850  
851 This returns a double, which represents the value of the element, interpreted as one of the following, in order:
852  
853 =over 4
854  
855 =item A time value
856  
857 =item A number
858  
859 =item NaN (C<undef>) if conversion is impossible
860  
861 =back
862  
863 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/valueAsNumber>
864  
865 =head2 webkitEntries
866  
867 This always returns C<undef> under perl.
868  
869 Under JavaScript, this returns an Array of C<FileSystemEntry> objects that describes the currently selected files or directories.
870  
871 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitEntries>
872  
873 =head2 webkitdirectory
874  
875 This returns or sets a boolean value, which represents the C<webkitdirectory> HTML attribute; if true, the file system picker interface only accepts directories instead of files.
876  
877 Example:
878  
879 <input type="file" id="filepicker" name="fileList" webkitdirectory multiple />
880 <ul id="listing"></ul>
881  
882 $doc->getElementById( 'filepicker' )->addEventListener( change => sub
883 {
884 my $output = $doc->getElementById( 'listing' );
885 my $files = event->target->files;
886  
887 for( my $i=0; $i < $files->length; $i++ )
888 {
889 my $item = $doc->createElement( 'li' );
890 $item->innerHTML = $files->[$i]->webkitRelativePath;
891 $output->appendChild( $item );
892 };
893 }, { capture => 0 });
894  
895 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory>
896  
897 =head2 width
898  
899 This returns or sets a string, which represents the element's width attribute, which defines the width of the image displayed for the button, if the value of type is image.
900  
901 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/width>
902  
903 =head2 willValidate
904  
905 Read-only.
906  
907 This returns or sets a boolean value, which represents whether the element is a candidate for constraint validation. It is false if any conditions bar it from constraint validation, including: its type is hidden, reset, or button; it has a C<datalist> ancestor; its disabled property is true.
908  
909 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/willValidate>
910  
911 =head1 METHODS
912  
913 Inherits methods from its parent L<HTML::Object::DOM::Element>
914  
915 =head2 mozGetFileNameArray
916  
917 Since this is a perl environment, this has no effect and always returns C<undef>.
918  
919 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/mozGetFileNameArray>
920  
921 =head2 mozSetFileArray
922  
923 Since this is a perl environment, this has no effect and always returns C<undef>.
924  
925 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/mozSetFileArray>
926  
927 =head2 setCustomValidity
928  
929 Sets a custom message to display if the input element's value is not valid.
930  
931 See L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity>
932  
933 =head2 stepDown
934  
935 Decrements the value by (step * n), where n defaults to 1 if not specified. Returns an C<HTML::Object::InvalidStateError> error:
936  
937 =over 4
938  
939 =item * if the method is not applicable to for the current type value,
940  
941 =item * if the value cannot be converted to a number or recognised as a L<DateTime> object when applicable,
942  
943 =item * if the resulting value is above the L</max> or below the L</min> set by their respective HTML attribute.
944  
945 =back
946  
947 If the element has no C<step> value, C<step> defaults to C<1>.
948  
949 Supported types and equivalent values are:
950  
951 =over 4
952  
953 =item * date
954  
955 Unit is 1 (day).
956  
957 <input type="date" min="2019-12-25" step="1" />
958  
959 This defaults to C<1970-01-01> if not value is set yet, but if a C<max> value is set and L</stepDown> is called, the initial value will be that of C<max> and if C<min> value is set and L</stepUp> is called, the initial value will be that of C<min>
960  
961 =item * month
962  
963 Unit is 1 (month).
964  
965 <input type="month" min="2019-12" step="12" />
966  
967 This defaults to C<1970-01> if not value is set yet, but if a C<max> value is set and L</stepDown> is called, the initial value will be that of C<max> and if C<min> value is set and L</stepUp> is called, the initial value will be that of C<min>
968  
969 =item * week
970  
971 Unit is 1 (week).
972  
973 <input type="week" min="2019-W23" step="2" />
974  
975 This defaults to C<1970-W1> if not value is set yet, but if a C<max> value is set and L</stepDown> is called, the initial value will be that of C<max> and if C<min> value is set and L</stepUp> is called, the initial value will be that of C<min>
976  
977 =item * time
978  
979 Unit is 60 (seconds).
980  
981 <input type="time" min="09:00" step="900" />
982  
983 This defaults to C<00:00> if not value is set yet, but if a C<max> value is set and L</stepDown> is called, the initial value will be that of C<max> and if C<min> value is set and L</stepUp> is called, the initial value will be that of C<min>
984  
985 =item * datetime-local
986  
987 Unit is 1 (second).
988  
989 <input type="datetime-local" min="2019-12-25T19:30:01" step="7" />
990  
991 This defaults to C<1970-01-01T00:00:00> if not value is set yet, but if a C<max> value is set and L</stepDown> is called, the initial value will be that of C<max> and if C<min> value is set and L</stepUp> is called, the initial value will be that of C<min>
992  
993 This also supports the following format C<2019-12-25T19:30>, i.e. without seconds, and C<2019-12-25T19>, i.e. without minutes or seconds
994  
995 =item * number
996  
997 Unit is 1.
998  
999 <input type="number" min="0" step="0.1" max="10" />
1000  
1001 =item * range
1002  
1003 Unit is 1.
1004  
1005 <input type="range" min="0" step="2" max="10" />
1006  
1007 =back
1008  
1009 Interestingly enough, if you have the following HTML:
1010  
1011 <input type="time" min="17:00" step="900" />
1012  
1013 and call C<stepUp>, it will set the value the first time to C<17:00>, then the second time to C<17:15>.
1014  
1015 However, the other way around is not true, i.e.
1016  
1017 <input type="time" max="17:00" step="900" />
1018  
1019 Then a call to C<stepDown> will not yield the value C<17:00>, but instead C<23:45>, the second time to C<17:00> and third time to C<16:45>. A L<bug report No 1749427 was filed to Mozilla|https://bugzilla.mozilla.org/show_bug.cgi?id=1749427> and L<to Chromium|https://bugs.chromium.org/p/chromium/issues/detail?id=1286160> on 2022-01-11 and is preemptively corrected here in this interface.
1020  
1021 Example:
1022  
1023 <!-- decrements by intervals of 900 seconds (15 minute) -->
1024 <input type="time" max="17:00" step="900" />
1025  
1026 <!-- decrements by intervals of 7 days (one week) -->
1027 <input type="date" max="2019-12-25" step="7" />
1028  
1029 <!-- decrements by intervals of 12 months (one year) -->
1030 <input type="month" max="2019-12" step="12" />
1031  
1032 $element->stepDown( [ $stepDecrement ] );
1033  
1034 Another example:
1035  
1036 <p>
1037 <label>Enter a number between 0 and 400 that is divisible by 5:
1038 <input type="number" step="5" id="theNumber" min="0" max="400" />
1039 </label>
1040 </p>
1041 <p>
1042 <label>Enter how many values of step you would like to decrement by or leave it blank:
1043 <input type="number" step="1" id="decrementer" min="-2" max="15" />
1044 </label>
1045 </p>
1046 <input type="button" value="Decrement" id="theButton" />
1047  
1048 # make the $button call the function
1049 my $button = $doc->getElementById('theButton');
1050 $button->addEventListener( click => sub
1051 {
1052 &stepondown();
1053 });
1054  
1055 sub stepondown
1056 {
1057 my $input = $doc->getElementById('theNumber');
1058 my $val = $doc->getElementById('decrementer')->value;
1059  
1060 # decrement with a parameter
1061 if( $val )
1062 {
1063 $input->stepDown( $val );
1064 }
1065 # or without a parameter. Try it with 0, 5, -2, etc.
1066 else
1067 {
1068 $input->stepDown();
1069 }
1070 }
1071  
1072 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/stepDown>, and L<Mozilla documentation on step|https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/step>
1073  
1074 =head2 stepUp
1075  
1076 Increments the value by (step * n), where n defaults to 1 if not specified. Returns an C<HTML::Object::InvalidStateError> error:
1077  
1078 =over 4
1079  
1080 =item * if the method is not applicable to for the current type value.,
1081  
1082 =item * if the element has no step value,
1083  
1084 =item * if the value cannot be converted to a number,
1085  
1086 =item * if the resulting value is above the max or below the min.
1087  
1088 =back
1089  
1090 Supported types and equivalent values are the same as for L</stepDown>:
1091  
1092 Example:
1093  
1094 <p>
1095 <label>Enter a number between 0 and 400 that is divisible by 5:
1096 <input type="number" step="5" id="theNumber" min="0" max="400" />
1097 </label>
1098 </p>
1099 <p>
1100 <label>Enter how many values of step you would like to increment by or leave it blank:
1101 <input type="number" step="1" id="incrementer" min="0" max="25" />
1102 </label>
1103 </p>
1104 <input type="button" value="Increment" id="theButton" />
1105  
1106 # make the $button call the function
1107 my $button = $doc->getElementById('theButton')
1108 $button->addEventListener( click => sub
1109 {
1110 &steponup();
1111 })
1112  
1113 sub steponup
1114 {
1115 my $input = $doc->getElementById('theNumber');
1116 my $val = $doc->getElementById('incrementer')->value;
1117 # increment with a parameter
1118 if( $val )
1119 {
1120 $input->stepUp( $val );
1121 }
1122 # or without a parameter. Try it with 0
1123 else
1124 {
1125 $input->stepUp();
1126 }
1127 }
1128  
1129 Another example:
1130  
1131 <input max="4096" min="1" name="size" step="2" type="number" value="4096" id="foo" />
1132  
1133 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/stepUp>, and L<Mozilla documentation on step|https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/step>
1134  
1135 =head1 EVENTS
1136  
1137 Event listeners for those events can also be found by prepending C<on> before the event type:
1138  
1139 For example, C<input> event listeners can be set also with C<oninput> method:
1140  
1141 $e->oninput(sub{ # do something });
1142 # or as an lvalue method
1143 $e->oninput = sub{ # do something };
1144  
1145 =head2 input
1146  
1147 Fires when the value of an C<input>, C<select>, or C<textarea> element has been changed. Note that this is actually fired on the L<HTML::Object::DOM::Element> interface and also applies to contenteditable elements, but we've listed it here because it is most commonly used with form input elements. Also available via the C<oninput> event handler property.
1148  
1149 Example:
1150  
1151 <input placeholder="Enter some text" name="name" />
1152 <p id="values"></p>
1153  
1154 my $input = $doc->querySelector('input');
1155 my $log = $doc->getElementById('values');
1156  
1157 $input->addEventListener( input => \&updateValue );
1158  
1159 sub updateValue
1160 {
1161 my $e = shift( @_ );
1162 $log->textContent = $e->target->value;
1163 }
1164  
1165 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event>
1166  
1167 =head2 invalid
1168  
1169 Fired when an element does not satisfy its constraints during constraint validation. Also available via the oninvalid event handler property.
1170  
1171 Example:
1172  
1173 <form action="#">
1174 <ul>
1175 <li><label>Enter an integer between 1 and 10: <input type="number" min="1" max="10" required></label></li>
1176 <li><input type="submit" value="submit"></li>
1177 </ul>
1178 </form>
1179 <p id="log"></p>
1180  
1181 my $input = $doc->querySelector('input');
1182 my $log = $doc->getElementById('log');
1183  
1184 $input->addEventListener( invalid => \&logValue );
1185 sub logValue
1186 {
1187 my $e = shift( @_ )l
1188 $log->textContent = $e->target->value;
1189 }
1190  
1191 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/invalid_event>
1192  
1193 =head2 search
1194  
1195 Fired when a search is initiated on an <input> of type="search". Also available via the onsearch event handler property.
1196  
1197 Example:
1198  
1199 # addEventListener version
1200 my $input = $doc->querySelector('input[type="search"]');
1201  
1202 $input->addEventListener( search => sub
1203 {
1204 say( "The term searched for was " . $input->value );
1205 })
1206  
1207 # onsearch version
1208 my $input = $doc->querySelector( 'input[type="search"]' );
1209  
1210 $input->onsearch = sub
1211 {
1212 say( "The term searched for was " + $input->value );
1213 })
1214  
1215 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/search_event>
1216  
1217 =head2 selectionchange
1218  
1219 Fires when the text selection in a C<input> element has been changed.
1220  
1221 Example:
1222  
1223 <div>Enter and select text here:<br />
1224 <input id="mytext" rows="2" cols="20" />
1225 /div>
1226 <div>selectionStart: <span id="start"></span></div>
1227 <div>selectionEnd: <span id="end"></span></div>
1228 <div>selectionDirection: <span id="direction"></span></div>
1229  
1230 my $myinput = $doc->getElementById( 'mytext' );
1231  
1232 $myinput->addEventListener( selectionchange => sub
1233 {
1234 $doc->getElementById( 'start' )->textContent = $myinput->selectionStart;
1235 $doc->getElementById( 'end' )->textContent = $myinput->selectionEnd;
1236 $doc->getElementById( 'direction' )->textContent = $myinput->selectionDirection;
1237 });
1238  
1239 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/selectionchange_event>
1240  
1241 =head1 DEPRECATED PROPERTIES
1242  
1243 =head2 align
1244  
1245 Provided with a string, and this sets or gets the HTML attribute that represents the alignment of the element. It is better to use CSS instead.
1246  
1247 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/align>
1248  
1249 =head2 useMap
1250  
1251 A string reflecting the usemap HTML attribute, containing the page-local URL of the C<<map>> element describing the image map to use. The page-local URL is a pound (hash) symbol (#) followed by the ID of the C<<map>> element, such as #my-map-element. The C<<map>> in turn contains C<<area>> elements indicating the clickable areas in the image.
1252  
1253 Example:
1254  
1255 <map name="mainmenu-map">
1256 <area shape="circle" coords="25, 25, 75" href="/index.html" alt="Return to home page">
1257 <area shape="rect" coords="25, 25, 100, 150" href="/index.html" alt="Shop">
1258 </map>
1259  
1260 <input usemap="#mainmenu-map" />
1261  
1262 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/useMap>
1263  
1264 =head1 AUTHOR
1265  
1266 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
1267  
1268 =head1 SEE ALSO
1269  
1270 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement>, L<Mozilla documentation on input element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input>
1271  
1272 =head1 COPYRIGHT & LICENSE
1273  
1274 Copyright(c) 2021 DEGUEST Pte. Ltd.
1275  
1276 All rights reserved
1277  
1278 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1279  
1280 =cut