Skip to content

Commit

Permalink
- SelectWidget now has a size attribute to support single select …
Browse files Browse the repository at this point in the history
…widgets

  that are not dropdowns.
  • Loading branch information
mcdonc authored and jandd committed Jun 11, 2011
1 parent 60b4df4 commit 2e20c10
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Next release

- Remove unused ``jquery.autocomplete.min.js`` file from static directory.

- SelectWidget now has a ``size`` attribute to support single select widgets
that are not dropdowns.

0.9 (2011-03-01)
----------------

Expand Down
3 changes: 2 additions & 1 deletion deform/templates/select.pt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<select name="${field.name}"
id="${field.oid}">
id="${field.oid}"
tal:attributes="size field.widget.size">
<option tal:repeat="(value, description) field.widget.values"
tal:attributes="selected value == cstruct;
class field.widget.css_class"
Expand Down
5 changes: 5 additions & 0 deletions deform/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ class SelectWidget(Widget):
element in the tuple is the value that should be returned when
the form is posted. The second is the display value.
size
The ``size`` attribute of the select input field (default:
``None``).
null_value
The value which represents the null value. When the null
value is encountered during serialization, the
Expand All @@ -619,6 +623,7 @@ class SelectWidget(Widget):
readonly_template = 'readonly/select'
null_value = ''
values = ()
size = None

def serialize(self, field, cstruct, readonly=False):
if cstruct in (null, None):
Expand Down
18 changes: 18 additions & 0 deletions deformdemo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,24 @@ class Schema(colander.Schema):
form = deform.Form(schema, buttons=('submit',))
return self.render_form(form)

@view_config(renderer='templates/form.pt', name='select_with_size')
@demonstrate('Select Widget (with size)')
def select_with_size(self):
choices = (
('', '- Select -'),
('habanero', 'Habanero'),
('jalapeno', 'Jalapeno'),
('chipotle', 'Chipotle')
)
class Schema(colander.Schema):
pepper = colander.SchemaNode(
colander.String(),
widget=deform.widget.SelectWidget(values=choices, size=2)
)
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
return self.render_form(form)

@view_config(renderer='templates/form.pt', name='checkboxchoice')
@demonstrate('Checkbox Choice Widget')
def checkboxchoice(self):
Expand Down
3 changes: 3 additions & 0 deletions deformdemo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,9 @@ def test_submit_selected(self):
captured = browser.get_text('css=#captured')
self.assertEqual(captured, "{'pepper': u'habanero'}")

class SelectWidgetWithSizeTests(SelectWidgetTests):
url = "/select_with_size/"

class TextInputWidgetTests(unittest.TestCase):
url = "/textinput/"
def test_render_default(self):
Expand Down

0 comments on commit 2e20c10

Please sign in to comment.