IContextSourceBinder doesn't bind to the context?

Little confused by this documentation

http://docs.plone.org/develop/addons/schema-driven-forms/customising-form-behaviour/vocabularies.html

which says " The context argument is the context of the form view".
But running it and looking at the code in zope.schema._field

                    if IChoice.providedBy(attribute):
                        # Choice must be bound before validation otherwise
                        # IContextSourceBinder is not iterable in validation
                        bound = attribute.bind(value)
                        bound.validate(getattr(value, name))

We can see the context is the value?

I remember a lot of gotchas regarding context, z3c.form and vocabularies. Context behaved differently

  • Depending on what kind of form you where dealing with (grok, z3c.form plain)

  • If you where using form, fieldsets, subforms, etc. and vocabulary was placed on a field which was not its most obvious use case

What might be applicable in one case, might not work in another, so there had to be all kinds of "traverse up in parents tree and hope there is a context and not a form element has broken the traversing tree and just in the case fall back to getSite() as it seems to work most of the time unless you are executing code outside normal HTTP request"

1 Like