Skip to content

Commit

Permalink
Merge pull request #26 from zopefoundation/list-form-controls
Browse files Browse the repository at this point in the history
Add a way to list all form controls without using internals
  • Loading branch information
davisagli committed Feb 3, 2017
2 parents d6756c1 + 7d32967 commit 1591831
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ CHANGES

- Fix passing a real file to ``add_file``.

- Add `controls` property to Form class to list all form controls.


5.1 (2017-01-31)
----------------
Expand Down
5 changes: 5 additions & 0 deletions src/zope/testbrowser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,11 @@ def getControl(self, label=None, name=None, index=None):
return disambiguate(intermediate, msg, index,
controlFormTupleRepr, available)

@property
def controls(self):
return list(self.browser._findAllControls(
[self._form], include_subcontrols=True))


def disambiguate(intermediate, msg, index, choice_repr=None, available=None):
if intermediate:
Expand Down
4 changes: 4 additions & 0 deletions src/zope/testbrowser/tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@ def test_subcontrols_can_be_selected_by_value():
GET /foo HTTP/1.1
...
>>> form_controls = browser.getForm(index=0).controls
>>> len(form_controls)
12
>>> checkboxes = browser.getControl(name='foo')
>>> checkboxes
<ListControl name='foo' type='checkbox'>
Expand Down

0 comments on commit 1591831

Please sign in to comment.