Skip to content

Commit

Permalink
Cover the case when field doesn't have a description.
Browse files Browse the repository at this point in the history
  • Loading branch information
nadako committed Feb 10, 2009
1 parent 8bf5eed commit cb3f14c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/z3c/form/hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,3 @@ def get(self):
return self.field.description
# None avoids rendering in templates
return None

def __repr__(self):
return '<%s %r>' % (self.__class__.__name__, self.__name__)
22 changes: 20 additions & 2 deletions src/z3c/form/hint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ Let's create a couple of simple widgets and forms first:
... textLine = zope.schema.TextLine(
... title=u'Title',
... description=u'A TextLine description')
...
... anotherLine = zope.schema.TextLine(
... title=u'Other')

>>> class Content(object):
... zope.interface.implements(IContent)
...
... textLine = None
... otherLine = None
...
>>> content = Content()

Expand All @@ -47,7 +51,7 @@ Let's create a couple of simple widgets and forms first:

>>> hintForm = HintForm(content, request)

As you can see, there is no title value set for our widget:
As you can see, there is no title value set for our widgets:

>>> hintForm.update()
>>> print hintForm.widgets['textLine'].render()
Expand All @@ -56,6 +60,12 @@ As you can see, there is no title value set for our widget:
class="text-widget required textline-field"
value="" type="text" />

>>> print hintForm.widgets['anotherLine'].render()
<input id="form-widgets-anotherLine"
name="form.widgets.anotherLine"
class="text-widget required textline-field"
value="" type="text" />

Let's configure our IValue ``hint`` adapter:

>>> from z3c.form.hint import FieldDescriptionAsHint
Expand All @@ -72,12 +82,20 @@ field description:
title="A TextLine description" value=""
type="text" />

If the field has no description as it is with the second one, no "title"
will be set for the widget:

>>> print hintForm.widgets['anotherLine'].render()
<input id="form-widgets-anotherLine"
name="form.widgets.anotherLine"
class="text-widget required textline-field"
value="" type="text" />

Check all fields
----------------

Just to make sure that all the widgets are handled correctly, we will
go trhough each of them. This sample can be useful if you need to
go through all of them. This sample can be useful if you need to
implement a JavaScript based hint concept:

>>> import datetime
Expand Down

0 comments on commit cb3f14c

Please sign in to comment.