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 #2341 (closed defect: fixed)

Opened 10 years ago

Last modified 9 years ago

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

Reported by: cd34 Owned by: percious
Priority: normal Milestone: 2.1rc1
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

comment:1 Changed 10 years ago 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.

comment:2 Changed 10 years ago 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>

comment:3 Changed 10 years ago by Chris Arndt

  • Owner changed from Chris Arndt to percious
  • Component changed from TG Widgets to ToscaWidgets

comment:4 Changed 10 years ago by jorge.vargas

  • Milestone set to 2.1

This seems like a valid bug.

comment:5 Changed 9 years ago by percious

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

i believe this was fixed in 0.9.8

comment:6 Changed 9 years ago by percious

  • Milestone changed from 2.1 to 2.1rc1
Note: See TracTickets for help on using tickets.