Re: [SOLVED] Deexterity: Validation of multiselection Field with input from Vocabulary

Andreas Mantke <[email protected]> Thu, 09 Apr 2015 19:39:01 +0200
Newsgroups gmane.comp.web.zope.plone.user
Message-ID <[email protected]>
Am 06.04.2015 um 17:19 schrieb Andreas Mantke:
> Hello,
>
> Am 05.03.2015 um 21:35 schrieb Andreas Mantke:
>> Hello David,
>>
>> Am 05.03.2015 um 08:06 schrieb David Glick (Plone):
>>> (...)

>>> 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
>>> e
>>> 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.
>>
> although this worked in the past it failed currently. I always get a
> red error message for the list-choice fields.
>
> I used a buildout with Plone 4.3.4  and Invalid from zope.interface-3.6.7.
>
> I tried with two other field types (schema.Text and schema.TextLine)
> with the same issue. I can't get Invalid/constraint satisfied. The
> same with a schema.Int field.
>
> Thanks for any hint in advance.

I fixed the issue. The function needed another line at the end:

'return True'


def isNotEmpty(value):
    if not value:
        raise Invalid(u'You must choose at least one category.')
    return True


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

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

_______________________________________________
Plone-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/plone-users