Skip to content

Commit

Permalink
Merge pull request #4116 from open-formulieren/issue/4096
Browse files Browse the repository at this point in the history
[#4096] Fix validation of hidden radio component
  • Loading branch information
sergei-maertens authored Apr 4, 2024
2 parents 77bb227 + 44d161e commit 26f547e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/openforms/formio/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def _remove_validations_from_field(self, field: serializers.Field) -> None:
field.min_length = None
field.max_length = None

case serializers.ChoiceField():
field.allow_blank = True

def _get_required(self) -> bool:
return any(field.required for field in self.fields.values())

Expand Down
31 changes: 31 additions & 0 deletions src/openforms/formio/tests/validation/test_radio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.test import SimpleTestCase, tag

from openforms.typing import JSONObject

from ...typing import RadioComponent
from .helpers import validate_formio_data


class RadioValidationTests(SimpleTestCase):

@tag("gh-4096")
def test_radio_hidden_required(self):
component: RadioComponent = {
"type": "radio",
"key": "radio",
"label": "Radio",
"values": [
{"label": "Opt1", "value": "opt1"},
{"label": "Opt2", "value": "opt2"},
],
"hidden": True,
"validate": {
"required": True,
},
}

# This happens when `clearOnHide` is `False`:
data: JSONObject = {"radio": ""}

is_valid, _ = validate_formio_data(component, data)
self.assertTrue(is_valid)

0 comments on commit 26f547e

Please sign in to comment.