Creating a custom short answer question that will be validated on the presence of some words and the compulsory absence of other words.
Intro
- Widgets and Custom Questions – part 2: where I described the use of the TextArea widget
- Extended TextArea Widget – more functionality: where I used a widget from Jim Leichliter to be able to reset the Short Answer question.
Widgets were meant for SWF-output only, including the widget by Jim (this one, he has some widgets that are also compatible with HTML5). Since Captivate 7 the TextArea widget got a companion, the ‘Scrolling Text Interaction’. Don’t be confused by the name, it is essentially the same widget, but compatible with HMTL5 output.
I found a challenge from a Captivate user on the forum, concerning the use of TextArea (or Scrolling Text) with a more complicated condition than the one I described in the previous blog posts: How to verify that a variable “does not contain” a value? As you probably know, the operators in the IF part of a conditional action are somehow limited: there is an operator ‘contains’ but no negative counterpart. My first reaction was to propose the use of JS, but my intuition told me I should also try with advanced actions. This post will explain how I solved that problem, and I was very happy when the King of Javascript in Captivate, Jim Leichliter posted his alternative with JS in the same thread, scroll down to find the script.
Here I will explain the conditional advanced action, and update my old screenshots with those valid for CP2017 and CP2019.
Challenge
The description of the problem: ” We are basically validating the content in the widget and showing appropriate feedback. Since the user can enter anything in the widget, we are only tracking the keywords. To be precise, we are trying to create an Advanced Action like this, where the text entry should contain the words Organizational, Behavioral, and Managerial but not the words Transformation and Non-Compliance. If the entry contains any of the “illegal” words, then incorrect feedback caption should appear.”
Translated: when the answer is submitted, the conditional action should show a Positive feedback when:
- the three first words are included in the text
- the last two words are not included in the text
If those conditions are not all fulfilled, the Negative feedback should be made visible.
Because of the missing operator ‘does not contain’ this cannot be done with one decision, one IF combination using AND, which explains why the user was stuck.
Solution ‘Divide et Impera’
After a long career as professor, this has become one of my mottoes: make it simple by splitting up the problem:
- Check first if all the conditions are fulfilled and store that result in a Boolean variable. There are a lot of Booleans in Captivate: variables that can have only two values, No/Yes, 0/1, False/True. I will mostly choose for the 0/1 combi. I created a user variable v_TA_OK with a default value of 0 (meaning all conditions are not yet OK)
- Show the appropriate feedback based on the value of that Boolean.
This was possible because of the typical way Advanced actions are executed in Captivate:
- all statements are executed in sequence and
- all decisions are executed in sequence
- the action is not stopped when a positive condition is met
This has led to a conditional advanced action with three decisions.
Example Movie
Watch this movie (rescalable HTML): it has 5 slides. After the title slide you will be able to enter 3 words that need to be included in the short answer, and two words that have to be excluded from the answer. On the third slide you can review the words, and eventually return to the previous slide to edit them. In the 4th slide, the question for the short answer appears. After submitting the answer the end slide will show if you succeeded or not.

Variables
To make the question more universal, I didn’t use literals for the words, but stored them into variables. These variables were created:
- v_OK: the Boolean variable explained above; default value = 0, will only be set to 1 if all conditions result in correct.
- v_answer to be associated with the Scrolling Text interaction that will capture the short answer (slide 4)
- v_in1, v_in2, v_in3 to store the words (can also be more words in one variable, but they’ll have to appear in that sequence) that have to be included in the answer, associated with the three green Scrolling Text interactions on slide 2.
- v_not1 and v_not2 for the words that are forbidden in the short answer (red Scrolling Text interactions on slide 2)
- v_null: an empty variable that is needed to create conditions for the other advanced actions (as the ones that check if all word fields have been filled); I will not explain those actions here; more info: Where is Null?
Advanced Actions and events
EmptyCheck
This action is triggered by the Success event of the Done button on slide 2. It checks if any of the Scrolling Text interactions has remained empty, and launches a message if that is the case:
SubmitAct
Triggered by the Success event of the Done button on the Short Answer slide (slide 4). It is the action with three decisions:
The first decision checks if all the words that have to be included are indeed in the short answer, using the AND operator. If that is the case the Boolean variable is set to 1. The second decision can override this, setting the var back to 0 if any of the words that are not allowed are included, hence the OR operator. The last decision will show one out of two Next buttons, the workflow I have invented many years ago in this article.
I detect that many users have taken over that workflow, which is great. If the short answer is correct, the Next button has an attached score (here 10 points), if not it has no score. Using this approach the score and percentage recorded in the Quizzing system variables will be correct.
EnterEnd
This action is triggered by the On Enter event of the last slide (which shows the feedback). To prove my previous statement about system variables I used the quizzing variable cpQuizInfoPassFail in this conditional action:
For the feedback message I used a shape with three states. The Normal state has no content. Although it is not possible to apply an effect to a state, you can apply an effect to an object after having changed to the wanted state.
Tips
Variables are case sensitive, and contrary to validation of a Text Entry Box it is not possible to get rid of that case sensitivity for variables associated with this interaction. If necessary you’ll have to create more decisions.
I wanted to emphasize the importance of sequence by this blog post, and the fact that Captivate will always evaluate all conditions/decisions. This is not always the case in normal programming languages. Trying to explain:
- The first decision is positive, variable v_OK will be set to 1, but there will not be ending of the condition
- If the first decision is negative, variable v_OK will remain at 0, no need to include an ELSE part. This means that the variable can never be set to 1 anymore, but the second decision will nevertheless be checked by CP.
- If both negative words are not included, nothing happens with the second decision, v_OK will keep its value 1 or 0 depending on the result of the first decision, because there is no ELSE part.
- If one of both negative words are included, the second decision will reset v_OK to 0, whatever its value was at the end of the first decision