From a2a639e071c635cc899eb5997020460d047d8424 Mon Sep 17 00:00:00 2001 From: bobslee Date: Thu, 23 May 2024 21:46:47 +0200 Subject: [PATCH] Improve the Component class conditional_visible_when method: Improve the Component class conditional_visible_when method, to also obtain a Dictionary for the value of triggering component. Remove the now redundant conditional_visible_when method from the selectboxesComponent, because a generic implementation is now in the Component class. --- CHANGELOG.md | 5 +++++ formiodata/components/component.py | 7 ++++++- formiodata/components/selectboxes.py | 11 ----------- pyproject.toml | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63f7225..3eae065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.0.1 + +Improve the `Component` class `conditional_visible_when` method, to also obtain a Dictionary for the value of triggering component.\ +Remove the now redundant `conditional_visible_when` method from the `selectboxesComponent`, because a generic implementation is now in the `Component` class. + ## 2.0.0 Fix `datetimeComponent` which is always stored as ISO with combined date, time and timezone.\ diff --git a/formiodata/components/component.py b/formiodata/components/component.py index 71934c0..d0fadd2 100644 --- a/formiodata/components/component.py +++ b/formiodata/components/component.py @@ -301,7 +301,12 @@ def conditional_visible_when(self): cond = self.raw['conditional'] triggering_component = self.component_owner.input_components[cond['when']] triggering_value = cond['eq'] - if triggering_component.value == triggering_value: + if isinstance( + triggering_component.value, dict + ) and triggering_component.value.get(triggering_value): + # E.g. triggering_component like selectboxesComponent + return cond["show"] + elif triggering_component.value == triggering_value: return cond['show'] else: return not cond['show'] diff --git a/formiodata/components/selectboxes.py b/formiodata/components/selectboxes.py index e4a5939..31394c6 100644 --- a/formiodata/components/selectboxes.py +++ b/formiodata/components/selectboxes.py @@ -20,14 +20,3 @@ def values_labels(self): val = {'key': b_val['value'], 'label': label, 'value': self.value.get(b_val['value'])} values_labels[b_val['value']] = val return values_labels - - def conditional_visible_when(self): - cond = self.raw['conditional'] - triggering_component = self.component_owner.input_components[cond['when']] - triggering_value = cond['eq'] - if triggering_component.value and triggering_component.value.get( - triggering_value - ): - return cond['show'] - else: - return not cond['show'] diff --git a/pyproject.toml b/pyproject.toml index 2fc3547..ba411b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "formio-data" -version = "2.0.0" +version = "2.0.1" homepage = "https://github.com/novacode-nl/python-formio-data" description = "formio.js JSON-data API" readme = "README.md"