Ticket #2341 (closed defect: fixed)

Opened 1 year ago

Last modified 7 months ago

tw.forms version 0.9.6 does not display validation errors with Form, ListForm and TableForm

Reported by: cd34 Assigned to: percious
Priority: normal Milestone: 2.1
Component: ToscaWidgets Version: 2.0.1
Severity: normal Keywords:
Cc:

Description

If one uses a WidgetsList?, and assigns a validator to a field widget, the error message that should be displayed when a validation fails, is not displayed. Validation does appear to work as the CSS classes for the fields that failed validation are modified.

a very basic piece of code placed in root.py in a new virtual environment with TG 2.0.1

I didn't see any documentation on this, but, Form doesn't display the label_text. I am not sure if this is intentional or not.

from tw.core import WidgetsList
from tw.forms import Form, ListForm, TableForm, TextField, TextArea, RadioButton
List, CheckBox, HiddenField, SingleSelectField, PasswordField
from tw.forms.validators import NotEmpty, Regex, Email
from pylons import c
from tg import redirect, validate, flash, request

class TestForm(TableForm):
    action = 'testadd'
    submit_text = 'Add test'

    class fields(WidgetsList):        #User = TextField()
        User = TextField(label_text='FTP Username', size=40, validator=NotEmpty())
        #User = TextField(label_text='FTP Username', size=40, validator=Email())

...

    @expose('tg201.templates.template')
    def form(self, **kw):
        c.form = TestForm()
        return dict(template='test',value=None)

    @validate(TestForm(), error_handler=form)
    def testadd(self, **kw):
        flash('great success')
        redirect('form')

template

<div xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude" 
      py:strip="">

${tmpl_context.form(value=value)}

</div>

If I install tw.forms-0.9.2.tar.gz or tw.forms-0.9.3dev-20090405.tar.gz, validation error messages are displayed.

Change History

08/01/09 19:00:37 changed by cd34

in core.py, line 90

error_at_request = RequestLocalDescriptor?('error',

doc = """Validation error for current request.""", default = None, qualify_with_id=True, )

If qualify_with_id=True, is commented out, validation works again.

08/01/09 19:03:54 changed by cd34

If Field labels should be displayed with Form, the following patch enables that.

--- /var/www/tg201orig/lib/python2.5/site-packages/tw.forms-0.9.7.2-py2.5.egg/tw/forms/templates/form.html	2009-07-30 17:58:43.263969462 -0400
+++ form.html	2009-07-30 20:33:51.769712506 -0400
@@ -11,7 +11,14 @@
         ${Markup(field.display(value_for(field), **args_for(field)))}
     </py:for>
     <py:for each="field in fields">
-        ${Markup(field.display(value_for(field), **args_for(field)))} <br />
+        <label id="${field.id}.label" 
+             py:with="required = [None,' required'][int(field.is_required)];
+             error = error_for(field);"
+             class="fieldlabel${required}"
+             py:if="field.label_text" py:content="field.label_text" />
+        ${Markup(field.display(value_for(field), **args_for(field)))} 
+        <span py:if="error and not error.error_dict" class="fielderror" py:content="error" />
+        <br />
     </py:for>
     </div>
 </form>

09/22/09 19:56:22 changed by Chris Arndt

  • owner changed from Chris Arndt to percious.
  • component changed from TG Widgets to ToscaWidgets.

11/17/09 08:28:50 changed by jorge.vargas

  • milestone set to 2.1.

This seems like a valid bug.

01/21/10 17:27:30 changed by percious

  • status changed from new to closed.
  • resolution set to fixed.

i believe this was fixed in 0.9.8