Re: Deexterity: Validation of multiselection Field with input from Vocabulary
"David Glick (Plone)" <david.glick-z4DKO/[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.user |
|---|---|
| Message-ID | <[email protected]> |
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
> defnoCategoryChoosen(data):
> ifdata.category_choice == []:
> raiseMissingCategory(_(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
)
------------------------------------------------------------------------------
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