Skip to content

Commit 418422d

Browse files
committed
Fix traversal for widget in multiwidgets that are added on the fly
Solves the use case of traversing a new widget that is not initialized by default. This mimics what happens when you click the add button.
1 parent eb53082 commit 418422d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/plone/z3cform/traversal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def traverse(self, name, ignored):
7272
# part should be integer index in list, look it up
7373
target = target.widgets[int(part)]
7474
except IndexError:
75-
raise TraversalError("'" + part + "' not in range")
75+
target = target.getWidget(int(part))
7676
except ValueError:
7777
# HACK: part isn't integer. Iterate through widgets to
7878
# find matching name. This is required for

src/plone/z3cform/traversal.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,16 @@ And traverse through to individual items.
154154
>>> age_widget.value
155155
'50'
156156

157-
Out of range errors are LocationErrors
157+
Sometimes you want to traverse to a widget that does not yet exist,
158+
e.g. the one that is added when you click the add button:
158159

159160
>>> traverser = get_traverser(Bar(),u"test-list-form")
160161
>>> age_widget = traverser.traverse('list_field.9', [])
161-
Traceback (most recent call last):
162-
File "<stdin>", line 1, in ?
163-
zope.location.interfaces.LocationError: "'9' not in range"
162+
Updating test form
163+
>>> age_widget
164+
<TextWidget 'form.widgets.list_field.9'>
165+
>>> age_widget.value
166+
''
164167

165168
Non-integer values are also LocationErrors
166169

0 commit comments

Comments
 (0)