Re: Deexterity: Validation of multiselection Field with input from Vocabulary

Christian Ledermann <[email protected]>
Newsgroups gmane.comp.web.zope.plone.user
Message-ID <CABCjzWrdeQCE4rf+u+S1iG18m4Nqo=8nni1rF2n3jMDdYOSiYw@mail.gmail.com>
iirc an empty choice field returns an emty list not None

On 1 March 2015 at 19:00, Andreas Mantke <[email protected]> wrote:
> 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
>



-- 
Best Regards,

Christian Ledermann

London - UK
Mobile : +44 7474997517

<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don’t drive species to extinction

2) Don’t destroy a habitat that species rely on.

3) Don’t change the climate in ways that will result in the above.

}<(((*>

------------------------------------------------------------------------------
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.