From 2d9e622f656a85c5e86f852ab098ae1400ae06b0 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 11 Aug 2010 09:31:41 +0200 Subject: [PATCH] check that user made a selection in a list-* field if it's required. Fixes #5829 --- src/common/dataforms.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common/dataforms.py b/src/common/dataforms.py index d1c82e589..0a053ab97 100644 --- a/src/common/dataforms.py +++ b/src/common/dataforms.py @@ -411,7 +411,11 @@ class ListSingleField(ListField, StringField): """ Covers list-single field """ - pass + def is_valid(self): + if not self.required: + return True + if not self.value: + return False class JidSingleField(ListSingleField): """ @@ -458,6 +462,12 @@ class ListMultiField(ListField): def iter_values(self): for element in self.getTags('value'): yield element.getData() + + def is_valid(self): + if not self.required: + return True + if not self.values: + return False class JidMultiField(ListMultiField): """ @@ -665,8 +675,6 @@ class SimpleDataForm(DataForm, DataRecord): # add if there is not if hasattr(f, 'value') and not f.value: f.value = '' - if hasattr(f, 'values') and not f.values: - f.values = [''] # Keep all required fields continue if (hasattr(f, 'value') and not f.value) or (hasattr(f, 'values') \