Deexterity: Validation of multiselection Field with input from Vocabulary

Andreas Mantke <[email protected]>
Newsgroups gmane.comp.web.zope.plone.user
Message-ID <[email protected]>
Hello,

I try to validate a Dexterity multiselection field that is created like
this:

category_choice = schema.List(
    title=_(u"Choose your categories"),
    value_type=schema.Choice(source=vocabCategories),
    required=True,
)


I tried to validate if this field is not empty. I wasn't successful by using @invariant with a function that raises an error message if data.category_choice is None.


@invariant
def noCategoryChoosen(data):
    if data.category_choice is None:
       raise MissingCategory(_(u"You must choose at least one category for your project"))



class MissingCategory(Invalid):
    __doc__ = _(u"You have not chosen a category for the project")


The test seemed to fail because the field has some value / data.

I tried the same with a constraint for the schema.List field with the same result.

Thanks for any hints in advance.

Regards,
Andreas

-- 
## Developer LibreOffice
## Freie Office-Suite für Linux, Mac, Windows
## http://LibreOffice.org
## Support the Document Foundation (http://documentfoundation.org)
## Meine Seite: http://www.amantke.de

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/

_______________________________________________
Plone-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/plone-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.