From ba62f8a2228de45a2bb7822e3efd8942d3b67531 Mon Sep 17 00:00:00 2001 From: Nicolas Dumazet <nicolas.dumazet@nexedi.com> Date: Thu, 8 Apr 2010 07:56:44 +0000 Subject: [PATCH] Bug #23: add a 'required' option to FileField. Defaults to False. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34353 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/Formulator/Validator.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/product/Formulator/Validator.py b/product/Formulator/Validator.py index b2a54282f9..a454413830 100644 --- a/product/Formulator/Validator.py +++ b/product/Formulator/Validator.py @@ -553,8 +553,22 @@ class MultiSelectionValidator(Validator): MultiSelectionValidatorInstance = MultiSelectionValidator() class FileValidator(Validator): + required = fields.CheckBoxField('required', + title='Required', + description=( + "Checked if the field is required; the " + "user has to fill in some data."), + default=0) + property_names = Validator.property_names + ['required'] + + message_names = Validator.message_names + ['required_not_found'] + required_not_found = 'Input is required but no input given.' + def validate(self, field, key, REQUEST): - return REQUEST.get(key, None) + value = REQUEST.get(key, None) + if field.get_value('required') and value in (None, ''): + self.raise_error('required_not_found', field) + return value FileValidatorInstance = FileValidator() -- 2.30.9