forms: do not fail normalization on 'none' validation (#67885)
This commit is contained in:
parent
4ace5a41e3
commit
cafa5aefe9
|
@ -1198,7 +1198,7 @@ class ValidationWidget(CompositeWidget):
|
|||
'title': _('IBAN'),
|
||||
'function': 'validate_iban',
|
||||
'error_message': _('Invalid IBAN'),
|
||||
'parse': lambda v: v.upper().strip().replace(' ', ''),
|
||||
'normalize_function': lambda v: v.upper().strip().replace(' ', ''),
|
||||
},
|
||||
),
|
||||
('regex', {'title': _('Regular Expression')}),
|
||||
|
@ -1328,6 +1328,13 @@ class ValidationWidget(CompositeWidget):
|
|||
return validation.get('value')
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_normalize_function(cls, validation):
|
||||
validation_method = cls.validation_methods.get(validation['type'])
|
||||
if validation_method and validation_method.get('normalize_function'):
|
||||
return validation_method['normalize_function']
|
||||
return lambda x: x # identity
|
||||
|
||||
@classmethod
|
||||
def get_html_input_type(cls, validation):
|
||||
validation_method = cls.validation_methods.get(validation['type'])
|
||||
|
@ -1371,9 +1378,8 @@ class WcsExtraStringWidget(StringWidget):
|
|||
self.error = self.validation_function_error_message or _('invalid value')
|
||||
|
||||
if self.field and self.value and not self.error and self.field.validation:
|
||||
parser = ValidationWidget.validation_methods[self.field.validation['type']].get('parse')
|
||||
if parser:
|
||||
self.value = parser(self.value)
|
||||
normalize = ValidationWidget.get_normalize_function(self.field.validation)
|
||||
self.value = normalize(self.value)
|
||||
|
||||
|
||||
class DateWidget(StringWidget):
|
||||
|
|
Loading…
Reference in New Issue