Skip to content

Commit

Permalink
Improve the Component class conditional_visible_when method:
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bobslee committed May 23, 2024
1 parent 17f2e98 commit a2a639e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.\
Expand Down
7 changes: 6 additions & 1 deletion formiodata/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
11 changes: 0 additions & 11 deletions formiodata/components/selectboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit a2a639e

Please sign in to comment.