Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check constraints on dexterity content types fields

Tags:

plone

I want to check during edit form saving process the value of a field verify some constraints

(understand calling a method where I can invalidate the form action)

like image 550
toutpt Avatar asked Aug 16 '11 20:08

toutpt


3 Answers

The field must be defined via schema (not supermodel), otherwise the field isn't visible in the schema. Once the field is defined in the schema, you may use a decorated function like the following to set a field validator:

@form.validator(field=IMySchema['title'])
def validateTitle(value):
    if value == value.upper():
        raise schema.ValidationError(u"Please don't shout")
like image 149
SteveM Avatar answered Nov 19 '22 16:11

SteveM


I'm pretty sure you can do this with a filesystem code dexterity type using zope.interface invariants.

like image 31
Ross Patterson Avatar answered Nov 19 '22 17:11

Ross Patterson


Take a look at the Dexterity Developer Manual, on the chapter dedicated to validators.

like image 1
hvelarde Avatar answered Nov 19 '22 16:11

hvelarde