diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e8e7a3..1d8df16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,17 @@ # Changelog +## 2.1.0 + +Fix `value_label` property (getter) in `selectComponent`, if no value is set. + +**WARNING - BACKWARD INCOMPATIBILITY**\ +This also changes `value_label` return value from `False` to `None` if no value is set.\ +So check whether to update any usage (code).\ +However no need when `None` is used in comparisons (`if` etc), which converts to boolean `False`. + ## 2.0.3 -Add `dataSrc` getter (property) in `selectboxesComponent`. +Add `dataSrc` property (getter) in `selectboxesComponent`. ## 2.0.2 diff --git a/formiodata/components/select.py b/formiodata/components/select.py index 1b87733..a408962 100644 --- a/formiodata/components/select.py +++ b/formiodata/components/select.py @@ -16,6 +16,8 @@ def multiple(self): @property def value_label(self): + if not self.value: + return None comp = self.component_owner.input_components.get(self.key) if self.dataSrc == 'url': label = self.value['label'] @@ -39,7 +41,7 @@ def value_label(self): else: return label else: - return False + return None @property def value_labels(self): diff --git a/pyproject.toml b/pyproject.toml index 45ad379..41ab8f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "formio-data" -version = "2.0.3" +version = "2.1.0" homepage = "https://github.com/novacode-nl/python-formio-data" description = "formio.js JSON-data API" readme = "README.md" diff --git a/tests/test_component_select_multiple.py b/tests/test_component_select_multiple.py index e2da659..b772497 100644 --- a/tests/test_component_select_multiple.py +++ b/tests/test_component_select_multiple.py @@ -39,7 +39,7 @@ def test_get_form(self): self.assertEqual(food.label, 'Favourite Food') self.assertEqual(food.value, ['mexican', 'chinese']) self.assertEqual(food.value_labels, ['Mexican', 'Chinese']) - self.assertEqual(food.value_label, False) + self.assertEqual(food.value_label, None) self.assertEqual(food.type, 'select') def test_get_form_data(self): @@ -47,7 +47,7 @@ def test_get_form_data(self): self.assertEqual(food.label, 'Favourite Food') self.assertEqual(food.value, ['mexican', 'chinese']) self.assertEqual(food.value_labels, ['Mexican', 'Chinese']) - self.assertEqual(food.value_label, False) + self.assertEqual(food.value_label, None) self.assertEqual(food.type, 'select') # i18n translations diff --git a/tests/test_component_select_one.py b/tests/test_component_select_one.py index 23862d8..e483732 100644 --- a/tests/test_component_select_one.py +++ b/tests/test_component_select_one.py @@ -48,6 +48,15 @@ def test_get_form_data(self): self.assertEqual(season.value_label, 'Autumn') self.assertEqual(season.type, 'select') + def test_empty_value(self): + season = self.form.input_components['favouriteSeason'] + self.assertEqual(season.label, 'Favourite Season') + self.assertEqual(season.value, 'autumn') + season.value = None + self.assertEqual(season.value, None) + self.assertEqual(season.value_label, None) + self.assertEqual(season.type, 'select') + # i18n translations def test_get_label_i18n_nl(self): season = self.builder_i18n_nl.input_components['favouriteSeason']