-
Notifications
You must be signed in to change notification settings - Fork 39
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
Custom DataManagers cause unexpected validator behavior #34
Comments
I m pretty sure that the current implementation can do anything what you need. But you need to think a bit different about how to use the z3c.form concept. If you like to provide a form for anythig else then the object traversal context. Or let's say for a context which provides another "object" you lik to edit etc. you can simply provide a form and update/render them with your custom "content" in your view. The context, request is a well defined concept in zope 3. The context its the traversable object where the view (page or form) adapts together with the request. It's a multi adapter on (context, request). There is nothing confusing about that. What we often do is to write a form for manage a (context, request) and call this form in a simply browser page like: class ComplexForm(BrowserPage):
This allows you to separate the traversal context and the form manipulating context aka content. I guess your problem is not a z3c.form problem, It's simply a miss match between the view traversal and form context. Does this answer your question? Or didn't I get your question right? If so, can you explain your usecase with a small sample? Regards Roger Ineichen |
Thanks @projekt01 - the issue is that in the scenario I describe above, to register the validator, the |
Consider what happens when the built-in (but not used by default)
DictionaryField
is registered as a data manager adapter to enable storing form data in aPersistentMapping
. We're assuming there's a customizedgetContent
method returning aPersistentMapping
as well of course.Upon validation, when a
context
parameter (discriminator) is passed tovalidator.WidgetValidatorDiscriminators
, it would have to bePersistentMapping
(or a suitable interface, such as IMapping), rather than the content object on which the form is invoked on (the 'view context'). Likewise, thez3c.form
baseSimpleValidator
initializes self with the same context, ie. here,PersistentMapping
.So the semantics of
context
change for z3c.form validation, depending on form customizations. I understand this may be by design, ie. that z3c.form considers "context" to be the (form) storage context.Even if so, that's not documented nor obvious or intuitive. I believe it to be confusing and unexpected to most people first learning to use z3c.form, given that 'context' in the Zope/Plone world is so pervasively used to refer to the acquisition context, often the parent content object.
It would be more consistent if validation context was always assigned the content object, regardless of how form is customized (and have the from storage referenced as something else). However practicality beats purity - I would not make a backwards-incompatible change to the signature of validator.WidgetValidatorDiscriminators without a large consensus from the community.
I would therefor propose that:
While I realize this addition would not end the original source of confusion, with proper documentation, I believe the change would be for the better.
The text was updated successfully, but these errors were encountered: