Re: 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 David, Am 05.03.2015 um 08:06 schrieb David Glick (Plone): > On 3/2/15 11:25 AM, Andreas Mantke wrote: >> Hello Christian, >> >> >> Am 02.03.2015 um 10:37 schrieb Christian Ledermann: >>> iirc an empty choice field returns an emty list not None >> thanks for your hint. That helped me a lot. >> I got the issue in my validation and it works in a default Dexterity >> form with now: >> @invariant >> def noCategoryChoosen(data): >> if data.category_choice == []: >> raise MissingCategory(_(u"You had to choose at least one category for your project.")) >> >> >> But if I use a similar validation within a Dexterity, that contains form.fieldsets, it behaves different. >> >> If I add a new Dexterity object I could solve one error message (validation error) after another and could save my Dexterity object at least. >> >> But if I edit a former such object (with added validation feature now) I'm not able to save the changes (choose a value for the List-Choice-Field). The errors message stays in eternity. >> > Some more options to try: > > 1. set min_length=1 on the List field and zope.schema will validate it > (but you won't get a custom validation message) > > 2. use a constraint on the field instead of an invariant on the schema > > from zope.interface import Invalid > > def isNotEmpty(value): > if not value: > raise Invalid(u'You must choose at least one category.') > > category_choice = List( > // ..., > constraint=isNotEmpty > ) thanks for that hint. The option with a constraint is much better. The user get the error message near to the field where his input is missing. 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