From 9d5181f953862eea4489106245a819bbae63e82d Mon Sep 17 00:00:00 2001 From: bobslee Date: Tue, 26 Sep 2023 13:42:07 +0200 Subject: [PATCH] Refactored conditionally_visible method and implement in selectboxesComponent. Refactored the Component class its conditionally_visible method, to call the following 2 methods which can be extended in component subclasses: - conditional_visible_json_when - conditional_visible_json_logic Implemented the conditional_visible_json_when method for the selectboxesComponent. Extended the unittest ConditionalVisibilitySimpleTestCase with simple conditional visibility for the selectboxesComponent. --- CHANGELOG.md | 9 + formiodata/components/component.py | 44 +- formiodata/components/selectboxes.py | 11 + pyproject.toml | 2 +- ...conditional_visibility_simple_builder.json | 1039 ++++++++++++----- ...al_visibility_simple_show_selectboxes.json | 20 + tests/test_conditional_visibility_simple.py | 8 + 7 files changed, 792 insertions(+), 341 deletions(-) create mode 100644 tests/data/test_conditional_visibility_simple_show_selectboxes.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 502f79e..b98f14a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 1.2.2 + +Refactored the `Component` class `conditionally_visible` method, to call the following 2 methods which can be extended in component subclasses: +- `conditional_visible_json_when` +- `conditional_visible_json_logic` + +Implemented the `conditional_visible_json_when` method for the `selectboxesComponent`.\ +Extended the unittest `ConditionalVisibilitySimpleTestCase` with simple conditional visibility for the `selectboxesComponent`. + ## 1.2.1 Fix `get_component_object` (Builder) method to handle `ModuleNotFoundError`.\ diff --git a/formiodata/components/component.py b/formiodata/components/component.py index deb1a27..8c3cd22 100644 --- a/formiodata/components/component.py +++ b/formiodata/components/component.py @@ -287,25 +287,9 @@ def conditionally_visible(self): try: cond = self.raw['conditional'] if cond.get('json'): - # Optional package - try: - from json_logic import jsonLogic - context = {'data': self._all_data} - try: - context['row'] = self.component_owner.row - except AttributeError: - pass # only datagrid rows have a "row" attribute - return jsonLogic(cond['json'], context) - except ImportError: - logger.warning(f'Could not load json logic extension; will not evaluate visibility of {self.__class__.__name__} {self.id} ("{self.key}")') - return True + return self.conditional_visible_json_logic() elif cond.get('when'): - triggering_component = self.component_owner.input_components[cond['when']] - triggering_value = cond['eq'] - if triggering_component.value == triggering_value: - return cond['show'] - else: - return not cond['show'] + return self.conditional_visible_when() except KeyError: # Unknown component or no 'when', 'eq' or 'show' property pass @@ -313,6 +297,30 @@ def conditionally_visible(self): # By default, it's visible return True + 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: + return cond['show'] + else: + return not cond['show'] + + def conditional_visible_json_logic(self): + # Optional package + try: + from json_logic import jsonLogic + context = {'data': self._all_data} + try: + context['row'] = self.component_owner.row + except AttributeError: + pass # only datagrid rows have a "row" attribute + cond = self.raw['conditional'] + return jsonLogic(cond['json'], context) + except ImportError: + logger.warning(f'Could not load json logic extension; will not evaluate visibility of {self.__class__.__name__} {self.id} ("{self.key}")') + return True + @property def is_visible(self): conditional = self.raw.get('conditional') diff --git a/formiodata/components/selectboxes.py b/formiodata/components/selectboxes.py index 31394c6..e4a5939 100644 --- a/formiodata/components/selectboxes.py +++ b/formiodata/components/selectboxes.py @@ -20,3 +20,14 @@ 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 1b6c376..3477b84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "formio-data" -version = "1.2.1" +version = "1.2.2" homepage = "https://github.com/novacode-nl/python-formio-data" description = "formio.js JSON-data API" readme = "README.md" diff --git a/tests/data/test_conditional_visibility_simple_builder.json b/tests/data/test_conditional_visibility_simple_builder.json index d2f78f1..e0fff10 100644 --- a/tests/data/test_conditional_visibility_simple_builder.json +++ b/tests/data/test_conditional_visibility_simple_builder.json @@ -1,334 +1,729 @@ { - "components": [ + "components": [ + { + "defaultValue": "", + "id": "exem1kg", + "inputType": "text", + "dataGridLabel": false, + "refreshOn": "", + "input": true, + "type": "textfield", + "overlay": { + "height": "", + "width": "", + "top": "", + "left": "", + "page": "", + "style": "" + }, + "attributes": { + }, + "logic": [], + "customConditional": "", + "conditional": { + "json": "", + "eq": "", + "when": "", + "show": "" + }, + "properties": { + }, + "tags": [], + "key": "textField", + "errorLabel": "", + "unique": false, + "validate": { + "unique": false, + "multiple": false, + "strictDateValidation": false, + "maxLength": "", + "minLength": "", + "json": "", + "customPrivate": false, + "custom": "", + "customMessage": "", + "pattern": "", + "required": false + }, + "validateOn": "change", + "allowCalculateOverride": false, + "calculateServer": false, + "calculateValue": "", + "customDefaultValue": "", + "clearOnHide": true, + "redrawOn": "", + "encrypted": false, + "case": "", + "dbIndex": false, + "protected": false, + "inputFormat": "plain", + "persistent": true, + "multiple": false, + "modalEdit": false, + "tableView": true, + "disabled": false, + "spellcheck": true, + "autofocus": false, + "mask": false, + "showCharCount": false, + "showWordCount": false, + "hideLabel": false, + "hidden": false, + "autocomplete": "", + "tabindex": "", + "customClass": "", + "allowMultipleMasks": false, + "inputMask": "", + "widget": { + "type": "input" + }, + "suffix": "", + "prefix": "", + "tooltip": "", + "description": "", + "placeholder": "", + "labelPosition": "top", + "label": "Text Field", + "addons": [], + "displayMask": "", + "truncateMultipleSpaces": false + }, + { + "defaultValue": "", + "id": "es2o4mb", + "inputType": "text", + "dataGridLabel": false, + "refreshOn": "", + "input": true, + "type": "textfield", + "overlay": { + "height": "", + "width": "", + "top": "", + "left": "", + "page": "", + "style": "" + }, + "attributes": { + }, + "logic": [], + "customConditional": "", + "conditional": { + "json": "", + "eq": "show!", + "when": "textField", + "show": true + }, + "properties": { + }, + "tags": [], + "key": "maybeTextField", + "errorLabel": "", + "unique": false, + "validate": { + "unique": false, + "multiple": false, + "strictDateValidation": false, + "maxLength": "", + "minLength": "", + "json": "", + "customPrivate": false, + "custom": "", + "customMessage": "", + "pattern": "", + "required": false + }, + "validateOn": "change", + "allowCalculateOverride": false, + "calculateServer": false, + "calculateValue": "", + "customDefaultValue": "", + "clearOnHide": true, + "redrawOn": "", + "encrypted": false, + "case": "", + "dbIndex": false, + "protected": false, + "inputFormat": "plain", + "persistent": true, + "multiple": false, + "modalEdit": false, + "tableView": true, + "disabled": false, + "spellcheck": true, + "autofocus": false, + "mask": false, + "showCharCount": false, + "showWordCount": false, + "hideLabel": false, + "hidden": false, + "autocomplete": "", + "tabindex": "", + "customClass": "", + "allowMultipleMasks": false, + "inputMask": "", + "widget": { + "type": "input" + }, + "suffix": "", + "prefix": "", + "tooltip": "", + "description": "", + "placeholder": "", + "labelPosition": "top", + "label": "Maybe Text Field", + "addons": [], + "displayMask": "", + "truncateMultipleSpaces": false + }, + { + "id": "eu84nnq", + "inputMask": "", + "inputFormat": "plain", + "inputType": "text", + "allowMultipleMasks": false, + "encrypted": false, + "calculateValue": "", + "customDefaultValue": "", + "dbIndex": false, + "dataGridLabel": false, + "refreshOn": "", + "persistent": true, + "unique": false, + "protected": true, + "defaultValue": null, + "multiple": false, + "input": true, + "type": "password", + "overlay": { + "height": "", + "width": "", + "top": "", + "left": "", + "page": "", + "style": "" + }, + "attributes": { + }, + "logic": [], + "customConditional": "", + "conditional": { + "json": "", + "eq": "hide!", + "when": "textField", + "show": false + }, + "properties": { + }, + "tags": [], + "key": "maybePassword", + "errorLabel": "", + "validate": { + "unique": false, + "multiple": false, + "strictDateValidation": false, + "maxLength": "", + "minLength": "", + "json": "", + "customPrivate": false, + "custom": "", + "customMessage": "", + "pattern": "", + "required": false + }, + "validateOn": "change", + "allowCalculateOverride": false, + "calculateServer": false, + "clearOnHide": true, + "redrawOn": "", + "case": "", + "modalEdit": false, + "tableView": false, + "disabled": false, + "spellcheck": true, + "autofocus": false, + "mask": false, + "showCharCount": false, + "showWordCount": false, + "hideLabel": false, + "hidden": false, + "autocomplete": "", + "tabindex": "", + "customClass": "", + "widget": { + "type": "input" + }, + "suffix": "", + "prefix": "", + "tooltip": "", + "description": "", + "placeholder": "", + "labelPosition": "top", + "label": "Maybe Password", + "addons": [], + "displayMask": "", + "truncateMultipleSpaces": false + }, + { + "label": "Columns", + "columns": [ { - "defaultValue": "", - "id": "eg5zo8f", - "inputType": "text", - "dataGridLabel": false, - "refreshOn": "", - "input": true, - "type": "textfield", - "overlay": { - "height": "", - "width": "", - "top": "", - "left": "", - "page": "", - "style": "" - }, - "attributes": { - }, - "logic": [], - "customConditional": "", - "conditional": { - "json": "", - "eq": "", - "when": "", - "show": "" - }, - "properties": { - }, - "tags": [], - "key": "textField", - "errorLabel": "", - "unique": false, - "validate": { - "unique": false, - "multiple": false, - "strictDateValidation": false, - "maxLength": "", - "minLength": "", - "json": "", - "customPrivate": false, + "components": [ + { + "label": "Job area", + "optionsLabelPosition": "right", + "tableView": false, + "defaultValue": { + "finance": false, + "sales": false, + "technology": false + }, + "values": [ + { + "label": "Finance", + "value": "finance", + "shortcut": "" + }, + { + "label": "Sales", + "value": "sales", + "shortcut": "" + }, + { + "label": "Technology", + "value": "technology", + "shortcut": "" + } + ], + "validate": { + "required": true, "custom": "", - "customMessage": "", - "pattern": "", - "required": false - }, - "validateOn": "change", - "allowCalculateOverride": false, - "calculateServer": false, - "calculateValue": "", - "customDefaultValue": "", - "clearOnHide": true, - "redrawOn": "", - "encrypted": false, - "case": "", - "dbIndex": false, - "protected": false, - "inputFormat": "plain", - "persistent": true, - "multiple": false, - "modalEdit": false, - "tableView": true, - "disabled": false, - "spellcheck": true, - "autofocus": false, - "mask": false, - "showCharCount": false, - "showWordCount": false, - "hideLabel": false, - "hidden": false, - "autocomplete": "", - "tabindex": "", - "customClass": "", - "allowMultipleMasks": false, - "inputMask": "", - "widget": { - "type": "input" - }, - "suffix": "", - "prefix": "", - "tooltip": "", - "description": "", - "placeholder": "", - "labelPosition": "top", - "label": "Text Field" - }, - { - "defaultValue": "", - "id": "e1tcwto", - "inputType": "text", - "dataGridLabel": false, - "refreshOn": "", - "input": true, - "type": "textfield", - "overlay": { - "height": "", - "width": "", - "top": "", - "left": "", - "page": "", - "style": "" - }, - "attributes": { - }, - "logic": [], - "customConditional": "", - "conditional": { - "json": "", - "eq": "show!", - "when": "textField", - "show": true - }, - "properties": { - }, - "tags": [], - "key": "maybeTextField", - "errorLabel": "", - "unique": false, - "validate": { - "unique": false, - "multiple": false, - "strictDateValidation": false, - "maxLength": "", - "minLength": "", - "json": "", "customPrivate": false, - "custom": "", - "customMessage": "", - "pattern": "", - "required": false - }, - "validateOn": "change", - "allowCalculateOverride": false, - "calculateServer": false, - "calculateValue": "", - "customDefaultValue": "", - "clearOnHide": true, - "redrawOn": "", - "encrypted": false, - "case": "", - "dbIndex": false, - "protected": false, - "inputFormat": "plain", - "persistent": true, - "multiple": false, - "modalEdit": false, - "tableView": true, - "disabled": false, - "spellcheck": true, - "autofocus": false, - "mask": false, - "showCharCount": false, - "showWordCount": false, - "hideLabel": false, - "hidden": false, - "autocomplete": "", - "tabindex": "", - "customClass": "", - "allowMultipleMasks": false, - "inputMask": "", - "widget": { - "type": "input" - }, - "suffix": "", - "prefix": "", - "tooltip": "", - "description": "", - "placeholder": "", - "labelPosition": "top", - "label": "Maybe Text Field" - }, - { - "id": "efraqi6", - "inputMask": "", - "inputFormat": "plain", - "inputType": "text", - "allowMultipleMasks": false, - "encrypted": false, - "calculateValue": "", - "customDefaultValue": "", - "dbIndex": false, - "dataGridLabel": false, - "refreshOn": "", - "persistent": true, - "unique": false, - "protected": true, - "defaultValue": null, - "multiple": false, - "input": true, - "type": "password", - "overlay": { - "height": "", - "width": "", - "top": "", - "left": "", - "page": "", - "style": "" - }, - "attributes": { - }, - "logic": [], - "customConditional": "", - "conditional": { - "json": "", - "eq": "hide!", - "when": "textField", - "show": false - }, - "properties": { - }, - "tags": [], - "key": "maybePassword", - "errorLabel": "", - "validate": { - "unique": false, - "multiple": false, "strictDateValidation": false, - "maxLength": "", - "minLength": "", - "json": "", - "customPrivate": false, - "custom": "", - "customMessage": "", - "pattern": "", - "required": false - }, - "validateOn": "change", - "allowCalculateOverride": false, - "calculateServer": false, - "clearOnHide": true, - "redrawOn": "", - "case": "", - "modalEdit": false, - "tableView": false, - "disabled": false, - "spellcheck": true, - "autofocus": false, - "mask": false, - "showCharCount": false, - "showWordCount": false, - "hideLabel": false, - "hidden": false, - "autocomplete": "", - "tabindex": "", - "customClass": "", - "widget": { - "type": "input" - }, - "suffix": "", - "prefix": "", - "tooltip": "", - "description": "", - "placeholder": "", - "labelPosition": "top", - "label": "Maybe Password" + "multiple": false, + "unique": false, + "onlyAvailableItems": false + }, + "key": "jobArea", + "type": "selectboxes", + "input": true, + "inputType": "checkbox", + "id": "epwo2of", + "placeholder": "", + "prefix": "", + "customClass": "", + "suffix": "", + "multiple": false, + "protected": false, + "unique": false, + "persistent": true, + "hidden": false, + "clearOnHide": true, + "refreshOn": "", + "redrawOn": "", + "modalEdit": false, + "dataGridLabel": false, + "labelPosition": "top", + "description": "", + "errorLabel": "", + "tooltip": "", + "hideLabel": false, + "tabindex": "", + "disabled": false, + "autofocus": false, + "dbIndex": false, + "customDefaultValue": "", + "calculateValue": "", + "calculateServer": false, + "widget": null, + "attributes": { + }, + "validateOn": "change", + "conditional": { + "show": null, + "when": null, + "eq": "" + }, + "overlay": { + "style": "", + "left": "", + "top": "", + "width": "", + "height": "" + }, + "allowCalculateOverride": false, + "encrypted": false, + "showCharCount": false, + "showWordCount": false, + "properties": { + }, + "allowMultipleMasks": false, + "addons": [], + "dataSrc": "values", + "authenticate": false, + "ignoreCache": false, + "template": "{{ item.label }}", + "data": { + "url": "" + }, + "fieldSet": false, + "inline": false + } + ], + "width": 6, + "offset": 0, + "push": 0, + "pull": 0, + "size": "md", + "currentWidth": 6 }, { - "id": "eqe1ke", - "rightIcon": "", - "leftIcon": "", - "allowMultipleMasks": false, - "properties": { - }, - "showWordCount": false, - "showCharCount": false, - "encrypted": false, - "allowCalculateOverride": false, - "overlay": { - "height": "", - "width": "", - "top": "", + "components": [ + { + "label": "Technology Function", + "optionsLabelPosition": "right", + "tableView": false, + "values": [ + { + "label": "Business Analyst", + "value": "analyst", + "shortcut": "" + }, + { + "label": "Developer", + "value": "developer", + "shortcut": "" + }, + { + "label": "DevOps", + "value": "devops", + "shortcut": "" + } + ], + "validate": { + "required": true, + "custom": "", + "customPrivate": false, + "strictDateValidation": false, + "multiple": false, + "unique": false, + "onlyAvailableItems": false + }, + "key": "technology", + "conditional": { + "show": true, + "when": "jobArea", + "eq": "technology" + }, + "type": "selectboxes", + "input": true, + "inputType": "checkbox", + "id": "epejfl", + "placeholder": "", + "prefix": "", + "customClass": "", + "suffix": "", + "multiple": false, + "defaultValue": null, + "protected": false, + "unique": false, + "persistent": true, + "hidden": false, + "clearOnHide": true, + "refreshOn": "", + "redrawOn": "", + "modalEdit": false, + "dataGridLabel": false, + "labelPosition": "top", + "description": "", + "errorLabel": "", + "tooltip": "", + "hideLabel": false, + "tabindex": "", + "disabled": false, + "autofocus": false, + "dbIndex": false, + "customDefaultValue": "", + "calculateValue": "", + "calculateServer": false, + "widget": null, + "attributes": { + }, + "validateOn": "change", + "overlay": { + "style": "", "left": "", - "style": "" - }, - "conditional": { - "eq": "", - "when": null, - "show": null + "top": "", + "width": "", + "height": "" + }, + "allowCalculateOverride": false, + "encrypted": false, + "showCharCount": false, + "showWordCount": false, + "properties": { + }, + "allowMultipleMasks": false, + "addons": [], + "dataSrc": "values", + "authenticate": false, + "ignoreCache": false, + "template": "{{ item.label }}", + "data": { + "url": "" + }, + "fieldSet": false, + "inline": false }, - "validate": { - "unique": false, - "multiple": false, - "strictDateValidation": false, - "customPrivate": false, + { + "label": "Sales Function", + "optionsLabelPosition": "right", + "tableView": false, + "defaultValue": { + "junior": false, + "medior": false, + "senior": false, + "accountManager": false, + "salesManager": false + }, + "values": [ + { + "label": "Account manager", + "value": "accountManager", + "shortcut": "" + }, + { + "label": "Sales manager", + "value": "salesManager", + "shortcut": "" + } + ], + "validate": { + "required": true, "custom": "", - "required": false - }, - "validateOn": "change", - "attributes": { - }, - "widget": { - "type": "input" - }, - "calculateServer": false, - "calculateValue": "", - "customDefaultValue": "", - "dbIndex": false, - "autofocus": false, - "disabled": false, - "tabindex": "", - "hideLabel": false, - "tooltip": "", - "errorLabel": "", - "description": "", - "labelPosition": "top", - "dataGridLabel": true, - "modalEdit": false, - "tableView": false, - "redrawOn": "", - "refreshOn": "", - "clearOnHide": true, - "hidden": false, - "persistent": false, - "unique": false, - "protected": false, - "defaultValue": null, - "multiple": false, - "suffix": "", - "customClass": "", - "prefix": "", - "placeholder": "", - "input": true, - "theme": "primary", - "disableOnInvalid": true, - "action": "submit", - "block": false, - "size": "md", - "key": "submit", - "label": "Submit", - "type": "button" + "customPrivate": false, + "strictDateValidation": false, + "multiple": false, + "unique": false, + "onlyAvailableItems": false + }, + "key": "sales", + "conditional": { + "show": true, + "when": "jobArea", + "eq": "sales" + }, + "type": "selectboxes", + "input": true, + "inputType": "checkbox", + "id": "er483x", + "placeholder": "", + "prefix": "", + "customClass": "", + "suffix": "", + "multiple": false, + "protected": false, + "unique": false, + "persistent": true, + "hidden": false, + "clearOnHide": true, + "refreshOn": "", + "redrawOn": "", + "modalEdit": false, + "dataGridLabel": false, + "labelPosition": "top", + "description": "", + "errorLabel": "", + "tooltip": "", + "hideLabel": false, + "tabindex": "", + "disabled": false, + "autofocus": false, + "dbIndex": false, + "customDefaultValue": "", + "calculateValue": "", + "calculateServer": false, + "widget": null, + "attributes": { + }, + "validateOn": "change", + "overlay": { + "style": "", + "left": "", + "top": "", + "width": "", + "height": "" + }, + "allowCalculateOverride": false, + "encrypted": false, + "showCharCount": false, + "showWordCount": false, + "properties": { + }, + "allowMultipleMasks": false, + "addons": [], + "dataSrc": "values", + "authenticate": false, + "ignoreCache": false, + "template": "{{ item.label }}", + "data": { + "url": "" + }, + "fieldSet": false, + "inline": false + } + ], + "width": 6, + "offset": 0, + "push": 0, + "pull": 0, + "size": "md", + "currentWidth": 6 } - ] + ], + "key": "columns39", + "type": "columns", + "input": false, + "tableView": false, + "id": "eyfga9n", + "placeholder": "", + "prefix": "", + "customClass": "", + "suffix": "", + "multiple": false, + "defaultValue": null, + "protected": false, + "unique": false, + "persistent": false, + "hidden": false, + "clearOnHide": false, + "refreshOn": "", + "redrawOn": "", + "modalEdit": false, + "dataGridLabel": false, + "labelPosition": "top", + "description": "", + "errorLabel": "", + "tooltip": "", + "hideLabel": false, + "tabindex": "", + "disabled": false, + "autofocus": false, + "dbIndex": false, + "customDefaultValue": "", + "calculateValue": "", + "calculateServer": false, + "widget": null, + "attributes": { + }, + "validateOn": "change", + "validate": { + "required": false, + "custom": "", + "customPrivate": false, + "strictDateValidation": false, + "multiple": false, + "unique": false + }, + "conditional": { + "show": null, + "when": null, + "eq": "" + }, + "overlay": { + "style": "", + "left": "", + "top": "", + "width": "", + "height": "" + }, + "allowCalculateOverride": false, + "encrypted": false, + "showCharCount": false, + "showWordCount": false, + "properties": { + }, + "allowMultipleMasks": false, + "addons": [], + "tree": false, + "lazyLoad": false, + "autoAdjust": false + }, + { + "id": "epjrupo", + "rightIcon": "", + "leftIcon": "", + "allowMultipleMasks": false, + "properties": { + }, + "showWordCount": false, + "showCharCount": false, + "encrypted": false, + "allowCalculateOverride": false, + "overlay": { + "height": "", + "width": "", + "top": "", + "left": "", + "style": "" + }, + "conditional": { + "eq": "", + "when": null, + "show": null + }, + "validate": { + "unique": false, + "multiple": false, + "strictDateValidation": false, + "customPrivate": false, + "custom": "", + "required": false + }, + "validateOn": "change", + "attributes": { + }, + "widget": { + "type": "input" + }, + "calculateServer": false, + "calculateValue": "", + "customDefaultValue": "", + "dbIndex": false, + "autofocus": false, + "disabled": false, + "tabindex": "", + "hideLabel": false, + "tooltip": "", + "errorLabel": "", + "description": "", + "labelPosition": "top", + "dataGridLabel": true, + "modalEdit": false, + "tableView": false, + "redrawOn": "", + "refreshOn": "", + "clearOnHide": true, + "hidden": false, + "persistent": false, + "unique": false, + "protected": false, + "defaultValue": null, + "multiple": false, + "suffix": "", + "customClass": "", + "prefix": "", + "placeholder": "", + "input": true, + "theme": "primary", + "disableOnInvalid": true, + "action": "submit", + "block": false, + "size": "md", + "key": "submit", + "label": "Submit", + "type": "button", + "addons": [] + } + ] } diff --git a/tests/data/test_conditional_visibility_simple_show_selectboxes.json b/tests/data/test_conditional_visibility_simple_show_selectboxes.json new file mode 100644 index 0000000..142acb5 --- /dev/null +++ b/tests/data/test_conditional_visibility_simple_show_selectboxes.json @@ -0,0 +1,20 @@ +{ + "textField": "", + "maybePassword": "", + "jobArea": { + "finance": false, + "sales": false, + "technology": true + }, + "submit": true, + "technology": { + "analyst": false, + "developer": true, + "devops": false + }, + "technologyFunction": { + "analyst": false, + "developer": true, + "devops": false + } +} diff --git a/tests/test_conditional_visibility_simple.py b/tests/test_conditional_visibility_simple.py index 2851e06..3c747f7 100644 --- a/tests/test_conditional_visibility_simple.py +++ b/tests/test_conditional_visibility_simple.py @@ -14,6 +14,7 @@ def setUp(self): self.builder_json = readfile('data', 'test_conditional_visibility_simple_builder.json') self.hide_password_form_json = readfile('data', 'test_conditional_visibility_simple_hide_password.json') + self.show_selectboxes_form_json = readfile('data', 'test_conditional_visibility_simple_show_selectboxes.json') self.show_textfield_form_json = readfile('data', 'test_conditional_visibility_simple_show_textfield.json') def test_conditionally_shown_form_elements_have_default_state_in_builder(self): @@ -22,6 +23,8 @@ def test_conditionally_shown_form_elements_have_default_state_in_builder(self): self.assertVisible(builder.input_components['textField']) self.assertNotVisible(builder.input_components['maybeTextField']) self.assertVisible(builder.input_components['maybePassword']) + self.assertNotVisible(builder.input_components['sales']) + self.assertNotVisible(builder.input_components['technology']) def test_conditionally_shown_form_elements_toggle_on_condition_being_met(self): builder = Builder(self.builder_json) @@ -36,6 +39,11 @@ def test_conditionally_shown_form_elements_toggle_on_condition_being_met(self): self.assertVisible(show_textfield_form.input_components['maybeTextField']) self.assertVisible(show_textfield_form.input_components['maybePassword']) + show_selectboxes_form = Form(self.show_selectboxes_form_json, builder) + self.assertVisible(show_selectboxes_form.input_components['jobArea']) + self.assertVisible(show_selectboxes_form.input_components['technology']) + self.assertNotVisible(show_selectboxes_form.input_components['sales']) + def test_conditionally_shown_form_elements_do_not_render_when_hidden(self): builder = Builder(self.builder_json)