Skip Menu |

This queue is for tickets about the HTML-DOM CPAN distribution.

Report information
The Basics
Id: 70499
Status: resolved
Priority: 0/
Queue: HTML-DOM

People
Owner: Nobody in particular
Requestors: martin [...] akm.com.au
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.048
Fixed in: (no value)



Subject: <button> elements are not supported by HTML::DOM::Element::Form
<button> elements are now supported by HTML::Form, could this element also be supported by HTML::DOM. I was only really interested in buttons of type='submit', so that was all i experimented with. There is a patch attached that adds this functionality, although it is a little broken, as it requires all buttons on the page to have a different value. Since if you click a button with a particular value, all buttons with that value will be submitted in the POST data, not just the one that was clicked. Or something like that, not 100% sure what was going on. Thanks, Martin
Subject: HTML::DOM::Element::Form.patch
--- Form.pm 2011-08-26 13:17:27.000000000 +1000 +++ Form.pm.orig 2011-08-26 15:10:55.000000000 +1000 @@ -121,8 +121,11 @@ grep($elem_elems{tag $_}, $self->descendants), @{ $self->{_HTML_DOM_mg_elems}||[] } ) { - next if (my $tag = tag $_) eq 'button'; # HTML::Form doesn't deal + #next if (my $tag = tag $_) eq 'button'; # HTML::Form doesn't deal # with <button>s. + # NOW IT DOES :) + my $tag = tag $_; + no warnings 'uninitialized'; # for 5.11.0 if(lc $_->attr('type') eq 'radio') { my $name = name $_; @@ -1231,6 +1234,56 @@ sub type { lc shift->attr('type') } sub value { shift->attr( value => @_) } +sub form_name_value +{ + my $self = shift; + my $type = $self->type; + if ($type =~ /^(image|submit)\z/) { + return unless $self->{_HTML_DOM_clicked}; + if($1 eq 'image') { + my $name = $self->name; + $name = length $name ? "$name." : ''; + return "${name}x" => $self->{_HTML_DOM_clicked}[0], + "${name}y" => $self->{_HTML_DOM_clicked}[1] + } + } + + my $name = $self->name; + return unless defined $name && length $name; + return if $self->disabled; + my $value = $self->value; + return unless defined $value; + return ($name => $value); +} + + +sub click { for(shift){ + my(undef,$x,$y) = @_; + defined or $_ = 1 for $x, $y; + local($$_{_HTML_DOM_clicked}) = [$x,$y]; + $_->trigger_event('click'); + return; +}} + +sub trigger_event { + my ($a,$evnt) = (shift,shift); + my $input_type = $a->type; + $a->SUPER::trigger_event( + $evnt, + $input_type =~ /^(?:(submi)|rese)t\z/ + ?( DOMActivate_default => + # I’m not using a closure here, because we + # don’t want the overhead of cloning it + # when it might not even be used. + (sub { (shift->target->form||return) + ->trigger_event('submit') }, + sub { (shift->target->form||return) + ->trigger_event('reset') }) + [!$1] + ) :(), + @_ + ); +} # ------- HTMLLabelElement interface ---------- #
On Fri Aug 26 01:26:42 2011, makman wrote: Show quoted text
> <button> elements are now supported by HTML::Form, could this element > also be supported by HTML::DOM. I was only really interested in buttons > of type='submit', so that was all i experimented with. > > There is a patch attached that adds this functionality, although it is a > little broken, as it requires all buttons on the page to have a different > value. Since if you click a button with a particular value, all buttons > with that value will be submitted in the POST data, not just the one that > was clicked. Or something like that, not 100% sure what was going on. > > Thanks, > Martin
Thank you for the patch. I’ll have a look at it and try to make a release in a week or so (a bit busy).
On Mon Aug 29 00:13:01 2011, SPROUT wrote: Show quoted text
> On Fri Aug 26 01:26:42 2011, makman wrote:
> > <button> elements are now supported by HTML::Form, could this
> element
> > also be supported by HTML::DOM. I was only really interested in
> buttons
> > of type='submit', so that was all i experimented with. > > > > There is a patch attached that adds this functionality, although it
> is a
> > little broken, as it requires all buttons on the page to have a
> different
> > value. Since if you click a button with a particular value, all
> buttons
> > with that value will be submitted in the POST data, not just the one
> that
> > was clicked. Or something like that, not 100% sure what was going
> on.
> > > > Thanks, > > Martin
> > Thank you for the patch. I’ll have a look at it and try to make a > release in a week or so (a bit > busy).
Thank you again. I’ve just released HTML::DOM 0.049, which supports <button>s. It was based on your patch, but required a few changes elsewhere, too.