Commit ba62f8a2 authored by Nicolas Dumazet's avatar Nicolas Dumazet

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
parent c84038c8
...@@ -553,8 +553,22 @@ class MultiSelectionValidator(Validator): ...@@ -553,8 +553,22 @@ class MultiSelectionValidator(Validator):
MultiSelectionValidatorInstance = MultiSelectionValidator() MultiSelectionValidatorInstance = MultiSelectionValidator()
class FileValidator(Validator): 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): 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() FileValidatorInstance = FileValidator()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment