showWhen Widget not working as expected

Forums: 

Hi, I'm trying to use the showWhen widget in the following semantics, but it just ends up printing the string [field:select:showWhen:inputType]

Any ideas what I'm doing wrong?

 

[ { "name": "categoriesList", "label": "Categories List", "importance": "high", "type": "list", "min": 1, "widgets": [ { "name": "VerticalTabs", "label": "Default", "importance": "high" } ], "field": { "name": "categoryGroup", "label": "Category Group", "type": "group", "fields": [ { "name": "categoryName", "label": "Category Name", "type": "text" }, { "name": "questionList", "label": "Question List", "type": "list", "min": 1, "field": { "name" :"questionsGroup", "label": "Questions Group", "type": "group", "fields": [ { "name": "questionType", "label": "Question Type", "importance": "high", "type": "select", "options": [ { "label": "Multiple choice", "value": "multipleChoice" }, { "label": "Text", "value": "text" } ], "default": "multipleChoice" }, { "name": "inputType", "label": "Multiple choice type", "importance": "high", "type": "select", "widget": "showWhen", "showWhen": { "rules": [ { "field": "questionType", "equals": "multipleChoice" } ] }, "options": [ { "label": "Multiple answers", "value": "checkbox" }, { "label": "Single answer", "value": "radio" } ], "default": "checkbox" }, { "name": "question", "label": "Question", "importance": "high", "type": "text" }, { "name": "alternatives", "label": "Answer alternatives", "type": "list", "importance": "high", "entity": "Alternative", "min": 2, "field": { "type": "group", "name": "alternative", "label": "Alternative", "fields": [ { "name": "text", "label": "Text", "importance": "high", "type": "text" }, { "name": "feedback", "type": "group", "label": "Feedback", "importance": "low", "optional": true, "fields": [ { "name": "chosenFeedback", "type": "text", "widget": "html", "label": "Message displayed if answer is selected", "importance": "low", "description": "Message will appear below the answer on \"continue\" if this answer is selected.", "optional": true, "tags": [ "strong", "em", "sub", "sup", "a", "code" ] }, { "name": "notChosenFeedback", "type": "text", "widget": "html", "label": "Message displayed if answer is not selected", "importance": "low", "description": "Message will appear below the answer on \"continue\" if this answer is not selected.", "optional": true, "tags": [ "strong", "em", "sub", "sup", "a", "code" ] } ] } ] } } ] } } ] } } ]
otacke's picture

Presumably you are not loading the show when widget library among the editorDependencies of library.json.

Correct! Thank you.

 

Is there a limitation of only being able to use one instance of the widget per semantics file, or semantics branch? I tried to use two but it just ignores the second one.

otacke's picture

No, you can have multiple ones. But the widget has in fact limitations.

  • There is a particular order in which the fields are instantiated (depth first if you think of semantics as a tree), and the field that is used for the rules must be loaded before the field with the widget.
  • ShowWhen widgets cannot be chained. A field that is used inside the rules may not have a showWhen widget itself.

Also just realised this is in the wrong forum, sorry bout that. Feel free to move it mods if it bothers you.

otacke's picture

I can't move it, I do not belong to H5P Group :-)

 

  • ShowWhen widgets cannot be chained. A field that is used inside the rules may not have a showWhen widget itself.

yep that was the one, cheers