fields: fix import field validation attribute from xml (#35488)
This commit is contained in:
parent
5626fc643f
commit
9ad71a9805
|
@ -509,6 +509,32 @@ def test_field_condition():
|
|||
assert len(f2.fields) == len(formdef.fields)
|
||||
assert f2.fields[0].condition == {'type': 'django', 'value': '1'}
|
||||
|
||||
def test_field_validation():
|
||||
formdef = FormDef()
|
||||
formdef.name = 'Foo'
|
||||
formdef.fields = [
|
||||
fields.StringField(type='string', id=1, label='Bar', size='40', validation={})
|
||||
]
|
||||
f2 = assert_xml_import_export_works(formdef)
|
||||
assert len(f2.fields) == len(formdef.fields)
|
||||
assert not f2.fields[0].validation
|
||||
|
||||
formdef.fields = [
|
||||
fields.StringField(type='string', id=1, label='Bar', size='40', validation=None)
|
||||
]
|
||||
formdef_xml = formdef.export_to_xml()
|
||||
f2 = FormDef.import_from_xml_tree(formdef_xml)
|
||||
assert len(f2.fields) == len(formdef.fields)
|
||||
assert not f2.fields[0].validation
|
||||
|
||||
formdef.fields = [
|
||||
fields.StringField(type='string', id=1, label='Bar', size='40',
|
||||
validation={'type': 'regex', 'value': r'\d'})
|
||||
]
|
||||
f2 = assert_xml_import_export_works(formdef)
|
||||
assert len(f2.fields) == len(formdef.fields)
|
||||
assert f2.fields[0].validation == formdef.fields[0].validation
|
||||
|
||||
def test_digest_template():
|
||||
formdef = FormDef()
|
||||
formdef.name = 'Foo'
|
||||
|
|
|
@ -672,7 +672,7 @@ class StringField(WidgetField):
|
|||
widget_class = WcsExtraStringWidget
|
||||
size = None
|
||||
extra_attributes = ['size']
|
||||
validation = None
|
||||
validation = {}
|
||||
data_source = {}
|
||||
|
||||
def perform_more_widget_changes(self, form, kwargs, edit=True):
|
||||
|
|
Loading…
Reference in New Issue