-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚑 [#4068] Fix broken backend validation
Backend validation was being applied more strict than equivalent in the frontend, which lead to submissions not being able to be completed. Fixes the following aspects: * Treat empty string is empty value for date field * Don't reject textfield (and derivatives) with multiple=True when items inside are null (treat them as empty value/string) * Allow empty lists for edit grid/repeating group when field is not required * Skip validation for layout components, they never get data * Ensure that empty string values for optional text fields are allowed (also covers derived fields) * Fixed validation error being returned that doesn't point to a particular component Backport-of: #4070
- Loading branch information
1 parent
f9796d4
commit b16e14d
Showing
13 changed files
with
247 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from django.test import SimpleTestCase, tag | ||
|
||
from ...typing import FieldsetComponent | ||
from .helpers import validate_formio_data | ||
|
||
|
||
class FieldSetValidationTests(SimpleTestCase): | ||
|
||
@tag("gh-4068") | ||
def test_fieldset_doesnt_require_value(self): | ||
# Fieldset is a layout component, so there's never any data to validate | ||
component: FieldsetComponent = { | ||
"type": "fieldset", | ||
"key": "fieldset", | ||
"label": "A field set", | ||
# don't ask me how, but somehow this got injected at some point. It's not | ||
# our new form builder, but it could be our own JS code in the backend in | ||
# src/openforms/js/components/formio_builder/WebformBuilder.js or they're | ||
# old forms that still suffer from #1724 | ||
"validate": { | ||
"required": True, | ||
}, | ||
"components": [ | ||
{ | ||
"type": "textfield", | ||
"key": "textfield", | ||
"label": "Text field", | ||
}, | ||
], | ||
} | ||
|
||
is_valid, _ = validate_formio_data(component, {}) | ||
|
||
self.assertTrue(is_valid) | ||
|
||
@tag("gh-4068") | ||
def test_hidden_fieldset_with_nested_required_fields(self): | ||
component: FieldsetComponent = { | ||
"type": "fieldset", | ||
"key": "fieldset", | ||
"label": "A field set", | ||
"components": [ | ||
{ | ||
"type": "textfield", | ||
"key": "textfield", | ||
"label": "Text field", | ||
"validate": {"required": True}, | ||
}, | ||
], | ||
"hidden": True, | ||
"conditional": { | ||
"show": True, | ||
"when": "missing", | ||
"eq": "never-triggered", | ||
}, | ||
} | ||
|
||
is_valid, _ = validate_formio_data(component, {"textfield": ""}) | ||
|
||
self.assertTrue(is_valid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
from typing_extensions import NotRequired | ||
|
||
from .base import Component | ||
from .dates import DatePickerConfig | ||
|
||
|
||
class DateComponent(Component): | ||
datePicker: DatePickerConfig | None | ||
datePicker: NotRequired[DatePickerConfig] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.