Gisle Aas <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] (Fran�ois Pons) writes:
> 
> > Gisle Aas <[EMAIL PROTECTED]> writes:
> > 
> > > I've been going through the backlog in my LWP folder today and managed
> > > to apply some of the patches found there.  I now have to return to my
> > > real work, but I still have lots of email I did not find time to look
> > > into.  The result so far has just been uploaded to CPAN as
> > > libwww-perl-5.77.  Feel free to remind me of important patches
> > > missing, especially if the patch also comes with updates to the test
> > > suite and documentation.
> > 
> > I wonder about the code in HTML::Form to handle forms with disabled state, which
> > are enabled back using JavaScript code. This is a simple modifications but not
> > handled, I will agree there are no RFC allowing this, which is more a hack than
> > anything else but nothing allow us (to me) to get the disabled input back on
> > live.
> > 
> > Does there are any reasons not using this very simple patch ?
> 
> I think the patch is wrong.  The data from a disabled input should not
> be sent back unless it is enabled.  Your patch effectively always
> enable them.  To get this right we would have to have to track
> enabledness and then provide a way of tweaking this attribute.

This a patch implemting this.  It exposes the 'readonly' and
'disabled' attribute for form inputs.  The patch has been applied :)

Regards,
Gisle


Index: lib/HTML/Form.pm
===================================================================
RCS file: /cvsroot/libwww-perl/lwp5/lib/HTML/Form.pm,v
retrieving revision 1.38
diff -u -p -r1.38 Form.pm
--- lib/HTML/Form.pm    23 Oct 2003 19:11:32 -0000      1.38
+++ lib/HTML/Form.pm    9 Apr 2004 14:14:30 -0000
@@ -188,10 +188,11 @@ sub push_input
        Carp::carp("Unknown input type '$type'") if $^W;
        $class = "TextInput";
     }
-    $class = "IgnoreInput" if exists $attr->{disabled};
     $class = "HTML::Form::$class";
+    my @extra;
+    push(@extra, readonly => 1) if $type eq "hidden";
 
-    my $input = $class->new(type => $type, %$attr);
+    my $input = $class->new(type => $type, %$attr, @extra);
     $input->add_to_form($self);
 }
 
@@ -769,6 +770,41 @@ sub value_names {
     return
 }
 
+=item $bool = $input->readonly
+
+=item $input->readonly( $bool )
+
+This method is used to get/set the value of the readonly attribute.
+You are allowed to modify the value of readonly inputs, but setting
+the value will generate some noise when warnings are enabled.  Hidden
+fields always start out readonly.
+
+=cut
+
+sub readonly {
+    my $self = shift;
+    my $old = $self->{readonly};
+    $self->{readonly} = shift if @_;
+    $old;
+}
+
+=item $bool = $input->disabled
+
+=item $input->disabled( $bool )
+
+This method is used to get/set the value of the disabled attribute.
+Disabled inputs do not contribute any key/value pairs for the form
+value.
+
+=cut
+
+sub disabled {
+    my $self = shift;
+    my $old = $self->{disabled};
+    $self->{disabled} = shift if @_;
+    $old;
+}
+
 =item $input->form_name_value
 
 Returns a (possible empty) list of key/value pairs that should be
@@ -781,6 +817,7 @@ sub form_name_value
     my $self = shift;
     my $name = $self->{'name'};
     return unless defined $name;
+    return if $self->{disabled};
     my $value = $self->value;
     return unless defined $value;
     return ($name => $value);
@@ -833,9 +870,8 @@ sub value
     my $old = $self->{value};
     $old = "" unless defined $old;
     if (@_) {
-       if (exists($self->{readonly}) || $self->{type} eq "hidden") {
-           Carp::carp("Input '$self->{name}' is readonly") if $^W;
-       }
+        Carp::carp("Input '$self->{name}' is readonly")
+           if $^W && $self->{readonly};
        $self->{value} = shift;
     }
     $old;
@@ -1068,6 +1104,7 @@ sub form_name_value
     return unless $clicked;
     my $name = $self->{name};
     return unless defined $name;
+    return if $self->{disabled};
     return ("$name.x" => $clicked->[0],
            "$name.y" => $clicked->[1]
           );
@@ -1154,6 +1191,7 @@ sub form_name_value {
 
     my $name = $self->name;
     return unless defined $name;
+    return if $self->{disabled};
 
     my $file = $self->file;
     my $filename = $self->filename;

Reply via email to