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

Andreas Mantke <[email protected]> Mon, 06 Apr 2015 17:19:22 +0200
Newsgroups gmane.comp.web.zope.plone.user
Message-ID <[email protected]>
Hello,

Am 05.03.2015 um 21:35 schrieb Andreas Mantke:
> 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
>> 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.

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