Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #476 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

Invalid fields on the page are empty after form validation

Reported by: jpaulofarias at gmail dot com Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TG Widgets Version:
Severity: normal Keywords:
Cc:

Description

When I use forms and some field is invalid, the resulting page shows an empty field for all fields that are invalid.

This bahavior is bad cause if the user made a single typo in a long field it will have to type it all over again.

The patch:

Index: turbogears/widgets/base.py
===================================================================
--- turbogears/widgets/base.py	(revision 584)
+++ turbogears/widgets/base.py	(working copy)
@@ -142,8 +142,8 @@
                 params[self.name] = self.validator.to_python(
                                     params.get(self.name, None))
             except validators.Invalid:
-                if params.has_key(self.name):
-                    del params[self.name]
+                #if params.has_key(self.name):
+                #    del params[self.name]
                 raise
     def source(self):
         return self.render("${%s}" % self.name, format="xml")

Change History

comment:1 Changed 13 years ago by jpaulofarias at gmail dot com

  • Summary changed from Invalid fields on the page are empty after form validation to [PATCH] Invalid fields on the page are empty after form validation

comment:2 Changed 13 years ago by kevin

  • Summary changed from [PATCH] Invalid fields on the page are empty after form validation to Invalid fields on the page are empty after form validation

I agree that not displaying the original entry value (where possible) is suboptimal. The problem with this fix (and maybe the new error handling mechanism will make this less of an issue) is that you can wind up passing an unexpected value into your method. For example, the method may be expecting an int, but all it gets is the string "foo" which could lead to other, not-validation-related errors.

I'll leave this ticket open, but I'm removing the [PATCH] marking because I think something more is needed.

comment:3 Changed 13 years ago by simon

 Discussion.

Test test.test_form_controllers.test_invalid_form_with_error_handling is set to fail until this issue is resolved.

comment:4 Changed 13 years ago by michele

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in r721 by Simon.

Note: See TracTickets for help on using tickets.