| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/Element/Select.pm | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## Created 2021/12/23 | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ## Modified 2022/09/18 | ||||||||||||||||||||||||||||||||||||||||||||||
| 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::Select; | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use parent qw( HTML::Object::DOM::Element ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use HTML::Object::DOM::Element::Shared qw( :select ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub init | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | $self->{tag} = 'select' if( !CORE::length( "$self->{tag}" ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | $self->{options} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | $self->{_select_reset} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | my $callback = sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | my $def = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Our children were modified from outside our package. | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # We need to check if it affects our rows and reset the cache accordingly | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | ▶ | unless( $def->{caller}->[0] eq ref( $self ) || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$def->{"caller"}[0] eq ref $self or $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Select"
MC/DC50%1/2
$def->{"caller"}[0] eq ref $self or $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Select"
$def->{"caller"}[0] eq ref $self
$def->{"caller"}[0] eq "HTML::Object::DOM::Element::Select"
Truth table66%2/3
A or B
A= $def->{"caller"}[0] eq ref $selfB= $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Select"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | $def->{caller}->[0] eq 'HTML::Object::DOM::Element::Select' ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | $self->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | return(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | $self->children->callback( add => $callback ); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | $self->children->callback( remove => $callback ); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | sub add | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=17 SCAR=47.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | message => sprintf( "At least 1 argument is required, but only %d was provided.", scalar( @_ ) ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | class => 'HTML::Object::SyntaxError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }) ) if( scalar( @_ ) < 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my( $elem, $pos ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
MC/DC0%0/2
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
$self->_is_a($elem, "HTML::Object::DOM::Element::Option")
$self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
Truth table33%1/3
A or B
A= $self->_is_a($elem, "HTML::Object::DOM::Element::Option")B= $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | message => "Element provided is neither a HTML::Object::DOM::Element::Option object nor a HTML::Object::DOM::Element::OptGroup object.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | }) ) if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element::Option' ) && !$self->_is_a( $elem => 'HTML::Object::DOM::Element::OptGroup' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my $options = $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | my $size = $options->size; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | if( defined( $pos ) && CORE::length( $pos ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pos and CORE::length $pos
MC/DC0%0/2
defined $pos and CORE::length $pos
defined $pos
CORE::length $pos
Truth table33%1/3
A and B
A= defined $posB= CORE::length $pos
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element::Option' ) && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$self->_is_a($elem, 'HTML::Object::DOM::Element::Option') || $self->_is_a($elem, 'HTML::Object::DOM::Element::OptGroup') || $self->_is_integer($pos)
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
MC/DC0%0/3
$self->_is_a($elem, 'HTML::Object::DOM::Element::Option') || $self->_is_a($elem, 'HTML::Object::DOM::Element::OptGroup') || $self->_is_integer($pos)
$self->_is_a($elem, "HTML::Object::DOM::Element::Option")
$self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
$self->_is_integer($pos)
Truth table0%0/4
A or B || C
A= $self->_is_a($elem, "HTML::Object::DOM::Element::Option")B= $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")C= $self->_is_integer($pos)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | !$self->_is_a( $elem => 'HTML::Object::DOM::Element::OptGroup' ) && | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | !$self->_is_integer( $pos ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return( $self->error({ | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | message => "The offset position before which to insert the element, if provided, must be an object or an integer, but I got '" . overload::StrVal( $pos ) . "'.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | }) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ▶ | elsif( $self->_is_a( $elem => 'HTML::Object::DOM::Element::Option' ) || | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
MC/DC0%0/2
$self->_is_a($elem, "HTML::Object::DOM::Element::Option") or $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
$self->_is_a($elem, "HTML::Object::DOM::Element::Option")
$self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
Truth table0%0/3
A or B
A= $self->_is_a($elem, "HTML::Object::DOM::Element::Option")B= $self->_is_a($elem, "HTML::Object::DOM::Element::OptGroup")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | $self->_is_a( $elem => 'HTML::Object::DOM::Element::OptGroup' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Check if it is an ancestor, as per the specifications | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $lineage = $self->lineage; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $lineagePos = $lineage->pos( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if( defined( $lineagePos ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return( $self->error({ | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | message => "Element to be added to this select element is an ancestor.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | }) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $tmpPos = $options->pos( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if( defined( $tmpPos ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $pos = $tmpPos; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | undef( $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if( $pos < 0 ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $pos = $pos + $size; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | elsif( $pos > $size ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | undef( $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | $elem->detach; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | $elem->parent( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | my $children = $self->children; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | if( defined( $pos ) && CORE::length( $pos ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pos and CORE::length $pos
MC/DC0%0/2
defined $pos and CORE::length $pos
defined $pos
CORE::length $pos
Truth table33%1/3
A and B
A= defined $posB= CORE::length $pos
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $kid = $options->index( $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $real_pos = $children->pos( $kid ); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $children->splice( $real_pos, 0, $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | $children->push( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | $self->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Note: property autofocus | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub autofocus : lvalue { return( shift->_set_get_property( 'autofocus', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
autofocus: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub blur { return; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blur: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # Note: method checkValidity is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Note: property disabled is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub focus { return; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
focus: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # Note: property form read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | ▶ | sub item { return( shift->options->index( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
item: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Note: property labels read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Note: property length | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub length : lvalue { return( shift->_set_get_property( 'length', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
length: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # Note: property multiple | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub multiple : lvalue { return( shift->_set_get_property( 'multiple', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
multiple: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # Note: property name is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Note: method namedItem is inherited from HTML::Object::DOM::Collection | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | sub namedItem { return( shift->options->namedItem( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
namedItem: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub onchange : lvalue { return( shift->on( 'change', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
onchange: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub oninput : lvalue { return( shift->on( 'input', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
oninput: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # Note: property options read-only | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # sub options { return( shift->_set_get_object( 'options', 'HTML::Object::DOM::Element::OptionsCollection', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | sub options | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 36 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 36 | ▶ | return( $self->{_select_options} ) if( $self->{_select_options} && !$self->_is_select_reset ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"_select_options"} and not $self->_is_select_reset
MC/DC100%2/2
$self->{"_select_options"} and not $self->_is_select_reset
$self->{"_select_options"}
not $self->_is_select_reset
Truth table100%3/3
A and not(B)
A= $self->{"_select_options"}B= not $self->_is_select_reset
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 21 | ▶ | my $list = $self->children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Element::Option' ) }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # The content of the collection is refreshed, but the collection object itself does not change, so the user can poll it | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 21 | ▶ | unless( $self->{_select_options} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | $self->_load_class( 'HTML::Object::DOM::Element::OptionsCollection' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | ▶ | $self->{_select_options} = HTML::Object::DOM::Element::OptionsCollection->new || | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'HTML::Object::DOM::Element::OptionsCollection'->new || (return $self->pass_error('HTML::Object::DOM::Element::OptionsCollection'->error))
MC/DC0%0/1
'HTML::Object::DOM::Element::OptionsCollection'->new || (return $self->pass_error('HTML::Object::DOM::Element::OptionsCollection'->error))
'HTML::Object::DOM::Element::OptionsCollection'->new
Truth table50%1/2
A
A= 'HTML::Object::DOM::Element::OptionsCollection'->new
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | return( $self->pass_error( HTML::Object::DOM::Element::OptionsCollection->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 21 | $self->{_select_options}->set( $list ); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 21 | $self->_remove_select_reset; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 21 | return( $self->{_select_options} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub remove | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=6 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | my $pos = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $pos and CORE::length "$pos" and $self->_is_integer($pos)
defined $pos and CORE::length "$pos"
MC/DC0%0/3
defined $pos and CORE::length "$pos" and $self->_is_integer($pos)
defined $pos
CORE::length "$pos"
$self->_is_integer($pos)
Truth table25%1/4
A and B and C
A= defined $posB= CORE::length "$pos"C= $self->_is_integer($pos)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | message => "Index value provided ($pos) is not an integer", | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | }) ) if( !defined( $pos ) || !CORE::length( "$pos" ) || !$self->_is_integer( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | my $options = $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | message => "Index value provided ($pos) is greater than the zero-based total number of options.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | }) ) if( $pos > $options->size ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | my $elem = $options->index( $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | my $real_pos = $self->children->pos( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | message => "Could not find the real index position of element found at offset '$pos'.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | }) ) if( !defined( $real_pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | $self->children->splice( $real_pos, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | $elem->parent( undef ); | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | $self->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | return( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Note: method reportValidity is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # Note: property required is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | sub reset | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 70 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 70 | ▶ | if( scalar( @_ ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 21 | $self->_reset_select; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | # Force the rebuilding of the collection of selected options | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 21 | CORE::delete( $self->{_selected_options} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | 21 | CORE::delete( $self->{selectedindex} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | 21 | return( $self->SUPER::reset( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 49 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # Note: property selectedIndex | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # This is called by the HTML::Object::DOM::Element::Option when selected | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # sub selectedIndex : lvalue { return( shift->_set_get_number( 'selectedindex', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | sub selectedIndex : lvalue { return( shift->_lvalue({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | set => sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my( $self, $val ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | message => "Index value provided is not an integer.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | }) ) if( !$self->_is_integer( $val ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $options = $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | message => "Index value provided is greater than the zero-based total number (" . $options->size . ") of options available.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | }) ) if( $val > $options->size ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $self->{selectedindex} = $val; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my $elem = $options->index( $val ); | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | message => "Somehow, the element found at position $val is not an HTML::Object::DOM::Element::Option object.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | }) ) if( !$self->_is_a( $elem => 'HTML::Object::DOM::Element::Option' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $elem->defaultSelected = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | get => sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | ▶ | return( $self->{selectedindex} ) if( $self->{selectedindex} && !$self->_is_select_reset ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"selectedindex"} and not $self->_is_select_reset
MC/DC0%0/2
$self->{"selectedindex"} and not $self->_is_select_reset
$self->{"selectedindex"}
not $self->_is_select_reset
Truth table33%1/3
A and not(B)
A= $self->{"selectedindex"}B= not $self->_is_select_reset
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # Get all options | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | my $options = $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | # Get all selected ones; could be empty | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | my $selected = $self->selectedOptions; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | ▶ | return if( $selected->is_empty ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # Get the first selected one | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | my $elem = $selected->index(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | # Find its index position among all options | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | my $pos = $options->pos( $elem ); | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | # and return it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | return( $self->{selectedindex} = $pos ); | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | ▶ | }, @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selectedIndex: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # Note: property selectedOptions read-only | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | sub selectedOptions | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 4 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selectedOptions: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | return( $self->{_selected_options} ) if( $self->{_selected_options} && !$self->_is_select_reset ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"_selected_options"} and not $self->_is_select_reset
MC/DC50%1/2
$self->{"_selected_options"} and not $self->_is_select_reset
$self->{"_selected_options"}
not $self->_is_select_reset
Truth table66%2/3
A and not(B)
A= $self->{"_selected_options"}B= not $self->_is_select_reset
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 2 | ▶ | my $list = $self->options->filter(sub{ $_->defaultSelected }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | $self->children->for(sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 14 | ▶ | my( $i, $elem ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | # The content of the collection is refreshed, but the collection object itself does not change, so the user can poll it | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | unless( $self->{_selected_options} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | ▶ | $self->_load_class( 'HTML::Object::DOM::Collection' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | $self->{_selected_options} = HTML::Object::DOM::Collection->new || | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'HTML::Object::DOM::Collection'->new || (return $self->pass_error('HTML::Object::DOM::Collection'->error))
MC/DC0%0/1
'HTML::Object::DOM::Collection'->new || (return $self->pass_error('HTML::Object::DOM::Collection'->error))
'HTML::Object::DOM::Collection'->new
Truth table50%1/2
A
A= 'HTML::Object::DOM::Collection'->new
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | return( $self->pass_error( HTML::Object::DOM::Collection->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | $self->{_selected_options}->set( $list ); | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | $self->_remove_select_reset; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | return( $self->{_selected_options} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Note: method setCustomValidity is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # Note: property size | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub size : lvalue { return( shift->_set_get_property( 'size', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # Note: property type read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # Note: property validationMessage read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # Note: property validity read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # Note: property value is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # Note: property willValidate read-only is inherited | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 37 | ▶ | sub _is_select_reset { return( CORE::length( shift->{_select_reset} ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_select_reset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 23 | ▶ | sub _remove_select_reset { return( CORE::delete( shift->{_select_reset} ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_select_reset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | sub _reset_select | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 21 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reset_select: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 21 | $self->{_select_reset}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | # Force it to recompute | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 21 | $self->options; | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | 21 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | HTML::Object::DOM::Element::Select - HTML Object DOM Select Class | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | use HTML::Object::DOM::Element::Select; | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | my $select = HTML::Object::DOM::Element::Select->new || | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | die( HTML::Object::DOM::Element::Select->error, "\n" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | v0.2.0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | This interface represents a C<<select>> HTML Element. These elements also share all of the properties and methods of other HTML elements via the L<HTML::Object::DOM::Element> interface. | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | =head1 INHERITANCE | ||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+ | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Select | | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +------------------------------------+ | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | =head1 PROPERTIES | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | Inherits properties from its parent L<HTML::Object::DOM::Element> | ||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | =head2 autofocus | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | A boolean value reflecting the autofocus L<HTML attribute|HTML::Object::DOM::Attribute>, which indicates whether the 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-associated element in a document can have this attribute specified. | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | <select id="mySelect" autofocus> | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | <option>Option 1</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | <option>Option 2</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # Check if the autofocus attribute on the <select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | my $hasAutofocus = $doc->getElementById('mySelect')->autofocus; | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/autofocus> | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | =head2 disabled | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | A boolean value reflecting the disabled L<HTML attribute|HTML::Object::DOM::Attribute>, which indicates whether the control is disabled. If it is disabled, it does not accept clicks. | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | <label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | Allow drinks? | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | <input id="allow-drinks" type="checkbox" /> | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | </label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | <label for="drink-select">Drink selection:</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | <select id="drink-select" disabled> | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | <option value="1">Water</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | <option value="2">Beer</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | <option value="3">Pepsi</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | <option value="4">Whisky</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | my $allowDrinksCheckbox = $doc->getElementById( 'allow-drinks' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | my $drinkSelect = $doc->getElementById( 'drink-select' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | $allowDrinksCheckbox->addEventListener( change => sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | if( $event->target->checked ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | $drinkSelect->disabled = 0; # false | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | $drinkSelect->disabled = 1; # true | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | }, { capture => 0}); | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/disabled> | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | =head2 form | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||
| 410 | An L<HTML::Object::DOM::Element::Form> referencing the form that this element is associated with. If the element is not associated with of a <form> element, then it returns C<undef>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | <form id="pet-form"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | <label for="pet-select">Choose a pet</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | <select name="pets" id="pet-select"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | <option value="dog">Dog</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | <option value="cat">Cat</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | <option value="parrot">Parrot</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | <button type="submit">Submit</button> | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | </form> | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||
| 425 | <label for="lunch-select">Choose your lunch</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | <select name="lunch" id="lunch-select"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | <option value="salad">Salad</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | <option value="sandwich">Sandwich</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | my $petSelect = $doc->getElementById( 'pet-select' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | my $petForm = $petSelect->form; # <form id="pet-form"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | my $lunchSelect = $doc->getElementById( 'lunch-select' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | my $lunchForm = $lunchSelect->form; # undef | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||
| 437 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/form> | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | =head2 labels | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | A L<HTML::Object::DOM::NodeList> of L<label elements|HTML::Object::DOM::Element::Label> associated with the element. | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | <label id="label1" for="test">Label 1</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | <select id="test"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | <option value="1">Option 1</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | <option value="2">Option 2</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | <label id="label2" for="test">Label 2</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | window->addEventListener( DOMContentLoaded => sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | my $select = $doc->getElementById( 'test' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | for( my $i = 0; $i < $select->labels->length; $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | say( $select->labels->[$i]->textContent ); # "Label 1" and "Label 2" | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/labels> | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||
| 465 | =head2 length | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | An unsigned long that reflects the number of L<option elements|HTML::Object::DOM::Element::Option> in this select element. | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/length> | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | =head2 multiple | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | A boolean value reflecting the multiple L<HTML attribute|HTML::Object::DOM::Attribute>, which indicates whether multiple items can be selected. | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/multiple> | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | =head2 name | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | A string reflecting the name L<HTML attribute|HTML::Object::DOM::Attribute>, containing the name of this control used by servers and DOM search functions. | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/name> | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | =head2 options | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | An L<OptionsCollection|HTML::Object::DOM::Element::OptionsCollection> representing the set of L<option elements|HTML::Object::DOM::Element::Option> contained by this element. | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | <label for="test">Label</label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | <select id="test"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | <option value="1">Option 1</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | <option value="2">Option 2</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 495 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | window->addEventListener( DOMContentLoaded => sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 499 | my $select = $doc->getElementById( 'test' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | for( my $i = 0; $i < $select->options->length; $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 501 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 502 | say( $select->options->[$i]->label ); # "Option 1" and "Option 2" | ||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/options> | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | =head2 required | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||
| 510 | A boolean value reflecting the required L<HTML attribute|HTML::Object::DOM::Attribute>, which indicates whether the user is required to select a value before submitting the form. | ||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||
| 512 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/required> | ||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | =head2 selectedIndex | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||
| 516 | A long reflecting the index of the first selected L<option element|HTML::Object::DOM::Element::Option>. The value C<undef> indicates no element is selected. | ||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | <p id="p">selectedIndex: 0</p> | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | <select id="select"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 522 | <option selected>Option A</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | <option>Option B</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | <option>Option C</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | <option>Option D</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 526 | <option>Option E</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||
| 529 | my $selectElem = $doc->getElementById('select'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | my $pElem = $doc->getElementById('p'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | # When a new <option> is selected | ||||||||||||||||||||||||||||||||||||||||||||||
| 533 | $selectElem->addEventListener( change => sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 534 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | my $index = $selectElem->selectedIndex; | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # Add that data to the <p> | ||||||||||||||||||||||||||||||||||||||||||||||
| 537 | $pElem->innerHTML = 'selectedIndex: ' . $index; | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | }) | ||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||
| 540 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/selectedIndex> | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||
| 542 | =head2 selectedOptions | ||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||
| 546 | An L<Collection|HTML::Object::DOM::Collection> representing the set of L<option elements|HTML::Object::DOM::Element::Option> that are selected. | ||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||
| 548 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/selectedOptions> | ||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||
| 550 | =head2 size | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||
| 552 | A long reflecting the size L<HTML attribute|HTML::Object::DOM::Attribute>, which contains the number of visible items in the control. The default is 1, unless multiple is true, in which case it is 4. | ||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||
| 554 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/size> | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||
| 556 | =head2 type | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||
| 558 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | A string represeting the form control's type. When multiple is true, it returns C<select-multiple>; otherwise, it returns C<select-one>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/type> | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||
| 564 | =head2 validationMessage | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||
| 568 | A string representing a localized message that describes the validation constraints that the control does not satisfy (if any). This attribute is the empty string if the control is not a candidate for constraint validation (willValidate is false), or it satisfies its constraints. | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||
| 570 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/validationMessage> | ||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||
| 572 | =head2 validity | ||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||
| 574 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||
| 576 | A L<ValidityState|HTML::Object::DOM::ValidityState> object reflecting the validity state that this control is in. | ||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||
| 578 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/validity> | ||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | =head2 value | ||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||
| 582 | A string reflecting the value of the form control. Returns the value property of the first selected option element if there is one, otherwise the empty string. | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||
| 584 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/value> | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | =head2 willValidate | ||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||
| 588 | Read-only. | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||
| 590 | A boolean value that indicates whether the button is a candidate for constraint validation. It is false if any conditions bar it from constraint validation. | ||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||
| 592 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/willValidate> | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||
| 594 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||
| 596 | Inherits methods from its parent L<HTML::Object::DOM::Element> | ||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||
| 598 | =head2 add | ||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||
| 600 | Provided with an C<item> and optionally an position offset C<before> which to insert the item and this adds an element to the collection of option elements for this select element. | ||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||
| 602 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||
| 604 | =item C<item> is an L<Option element|HTML::Object::DOM::Element::Option> or L<OptGroup element|HTML::Object::DOM::Element::OptGroup> | ||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||
| 606 | =item C<before> is optional and an element of the collection, or an index of type long, representing the item should be inserted before. If this parameter is C<undef> (or the index does not exist), the new element is appended to the end of the collection. | ||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||
| 608 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||
| 612 | my $sel = $doc->createElement( 'select' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 613 | my $opt1 = $doc->createElement( 'option' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 614 | my $opt2 = $doc->createElement( 'option' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||
| 616 | $opt1->value = 1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 617 | $opt1->text = "Option: Value 1"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||
| 619 | $opt2->value = 2; | ||||||||||||||||||||||||||||||||||||||||||||||
| 620 | $opt2->text = "Option: Value 2"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||
| 622 | # No second argument; no 'before' argument | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | $sel->add( $opt1, undef ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 624 | # Equivalent to above | ||||||||||||||||||||||||||||||||||||||||||||||
| 625 | $sel->add( $opt2 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||
| 627 | Produces the following, conceptually: | ||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||
| 629 | <select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 630 | <option value="1">Option: Value 1</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 631 | <option value="2">Option: Value 2</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 632 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||
| 634 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/add> | ||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||
| 636 | =head2 blur | ||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||
| 638 | Under perl, of course, this does nothing. | ||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||
| 640 | Under JavaScript, this removes the input focus from this element. This method is now implemented on L<HTML::Object::DOM::Element>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||
| 642 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/blur> | ||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||
| 644 | =head2 checkValidity | ||||||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||||||
| 646 | Checks whether the element has any constraints and whether it satisfies them. If the element fails its constraints, the browser fires a cancelable invalid event at the element (and returns false). | ||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||
| 648 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/checkValidity> | ||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||
| 650 | =head2 focus | ||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||
| 652 | Under perl, of course, this does nothing. | ||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||
| 654 | Under JavaScript, this gives input focus to this element. This method is now implemented on L<HTML::Object::DOM::Element>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||
| 656 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/focus> | ||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||
| 658 | =head2 item | ||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||
| 660 | Gets an item from the options collection for this L<select element|HTML::Object::DOM::Select> by providing a zero-based index position. | ||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||
| 662 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||
| 664 | <select id="myFormControl"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 665 | <option id="o1">Opt 1</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 666 | <option id="o2">Opt 2</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 667 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||
| 669 | # Returns the OptionElement representing #o2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 670 | my $sel = $doc->getElementById( 'myFormControl' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 671 | my $elem1 = $sel->item(1); # Opt 2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||
| 673 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/item> | ||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||
| 675 | =head2 namedItem | ||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||
| 677 | Gets the item in the options collection with the specified name. The name string can match either the id or the name attribute of an option node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||
| 679 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||
| 681 | <select id="myFormControl"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 682 | <option id="o1">Opt 1</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 683 | <option id="o2">Opt 2</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 684 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||
| 686 | my $elem1 = $doc->getElementById( 'myFormControl' )->namedItem( 'o1' ); # Returns the OptionElement representing #o1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||
| 688 | This is, in effect, a shortcut for C<$select->options->namedItem> | ||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||
| 690 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/namedItem> | ||||||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||||||
| 692 | =head2 remove | ||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||
| 694 | Removes the element at the specified index (zero-based) from the options collection for this select element and return it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||
| 696 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||
| 698 | <select id="existingList" name="existingList"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 699 | <option value="1">Option: Value 1</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 700 | <option value="2">Option: Value 2</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 701 | <option value="3">Option: Value 3</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 702 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||
| 704 | my $sel = $doc->getElementById( 'existingList' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 705 | my $removed = $sel->remove(1); | ||||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||
| 707 | HTML is now: | ||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||
| 709 | <select id="existingList" name="existingList"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 710 | <option value="1">Option: Value 1</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 711 | <option value="3">Option: Value 3</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 712 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/remove> | ||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||
| 716 | =head2 reportValidity | ||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||
| 718 | This method reports the problems with the constraints on the element, if any, to the user. If there are problems, it fires a cancelable invalid event at the element, and returns false; if there are no problems, it returns true. | ||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||
| 720 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/reportValidity> | ||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||
| 722 | =head2 setCustomValidity | ||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||
| 724 | Sets the custom validity message for the selection element to the specified message. Use the empty string to indicate that the element does not have a custom validity error. | ||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||
| 726 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/setCustomValidity> | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||
| 728 | =head1 EVENTS | ||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||
| 730 | Event listeners for those events can also be found by prepending C<on> before the event type: | ||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||
| 732 | C<click> event listeners can be set also with C<onclick> method: | ||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||
| 734 | $e->onclick(sub{ # do something }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 735 | # or as an lvalue method | ||||||||||||||||||||||||||||||||||||||||||||||
| 736 | $e->onclick = sub{ # do something }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||
| 738 | Note that, under perl, almost no event are fired, but you can trigger them yourself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||
| 740 | =head2 change | ||||||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||||||
| 742 | Fires when the user selects an option, but since there is no user interaction, this event is fired when the C<selectedIndex> value changes, which you can change yourself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||
| 744 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | <label>Choose an ice cream flavor: | ||||||||||||||||||||||||||||||||||||||||||||||
| 747 | <select class="ice-cream" name="ice-cream"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 748 | <option value="">Select One …</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 749 | <option value="chocolate">Chocolate</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 750 | <option value="sardine">Sardine</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 751 | <option value="vanilla">Vanilla</option> | ||||||||||||||||||||||||||||||||||||||||||||||
| 752 | </select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 753 | </label> | ||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||
| 755 | <div class="result"></div> | ||||||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||||||
| 757 | my $selectElement = $doc->querySelector('.ice-cream'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||||||
| 759 | $selectElement->addEventListener( change => sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 760 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 761 | my $result = $doc->querySelector( '.$result' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 762 | $result->textContent = "You like " . $event->target->value; | ||||||||||||||||||||||||||||||||||||||||||||||
| 763 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||
| 765 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event> | ||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||
| 767 | =head2 input | ||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||
| 769 | Fires when the value of an <input>, <select>, or <textarea> element has been changed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||
| 771 | See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event> | ||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||
| 773 | =head2 reset | ||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||
| 775 | Reset the cache flag so that some data will be recomputed. The cache is design to avoid doing useless computing repeatedly when there is no change of data. | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||
| 777 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||
| 779 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||||||
| 781 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||
| 783 | L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement>, L<Mozilla documentation on select element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select> | ||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||
| 785 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||||
| 787 | Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||
| 789 | All rights reserved | ||||||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||||||
| 791 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||
| 793 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||