-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(z3cformdoc): One can't change widget factories in update() any more #247
Conversation
When using autoform, the widgets get initialized before the update method is run. Therefor one must override the widgetFactory in updateWidgets.
fix(z3cformdoc): One can't change widget factories in update() any more
@@ -676,7 +674,7 @@ Example from `collective.z3cform.datagridfield_demos <https://github.com/collect | |||
|
|||
grok.name('demo-collective.z3cform.datagrid-block-edit') | |||
|
|||
def update(self): | |||
def updateWidgets(self): | |||
# Set a custom widget for a field for this form instance only | |||
self.fields['address'].widgetFactory = BlockDataGridFieldFactory | |||
super(EditForm9, self).update() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're changing this to updateWidgets, you need to call updateWidgets on the super too, or you'll get into a loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed (I guess) in 982af27
@davisagli you said that calling update() in updateWidgets would make the view run in circles. That made me wonder and look more into the issue. https://github.com/plone/plone.autoform/blob/master/plone/autoform/view.py#L45 |
Here's the order of operations when update gets called on most autoforms:
You pointed at plone.autoform.view.WidgetsView, which is used for views (not forms) that make use of z3c.form widgets in display mode, and it works somewhat differently. It does seem wrong that it calls updateWidgets before calling update, but I guess Martin structured it this way so that it would with views that are doing their own (non-widget-related) initialization in update. Overriding updateWidgets like in this PR should still work. |
When using autoform, the widgets get initialized before the update
method is run. Therefore one must override the widgetFactory in updateWidgets.
Dunno if this was intended, but thats the way it works now.