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 ---------- #