Advanced features
7.1 Including Java Code¶
This functionality is intended for advanced users only. Any deployed code should be thoroughly tested before launching the survey. The code is written in Java and can include whatever logic is needed to fulfill the requirement.
There are two main objectives for this functionality:
- Implement custom validation for the questions displayed in the current step.
- Configure custom conditions for use in the tree structure definition.
7.1.1 Validation¶
Below is an example of how to use this functionality. The code checks whether questions P1 and P4 were answered with the same option. If so, it sets an error that will be displayed to the survey respondent.
Note the validacionOk variable, which must initially be set to true. If an error condition is detected, set it to false. This is a powerful feature for implementing custom validation logic.
import Clases.*;
boolean validacionOk = true;
Pregunta pregunta1 = encuesta.getPregunta("P1");
Pregunta pregunta4 = encuesta.getPregunta("P4");
boolean isContestadaObj1 = pregunta1.isContestadaUser();
boolean isContestadaObj4 = pregunta4.isContestadaUser();
if (pregunta1.getCodIndexAnswerFromUser().equals(pregunta4.getCodIndexAnswerFromUser())) {
pregunta4.setMensajeError("La pregunta 1 y la pregunta 4 no pueden ser contestadas con la misma opcion");
validacionOk = false;
}
return validacionOk;
Since the code is associated with a step, deleting a step from the tree structure also deletes the associated code. It is recommended to keep a local backup of this code so it can be reassigned to another step if needed.
7.1.2 Defining Conditions¶
You can define custom conditions within a step for use later in the survey tree structure. Up to 3 custom conditions can be configured: condUser1, condUser2, and condUser3.
The following example shows a simple script that sets custom conditions based on the answers to question P1:
import Clases.*;
boolean validacionOk = true;
ps.remove("condUser1");
ps.remove("condUser2");
ps.remove("condUser3");
Pregunta preg1;
preg1 = encuesta.getPregunta("P1");
Vector respuestas = preg1.getRespuestas();
Respuesta resp1 = respuestas.elementAt(0);
if (resp1.isSennalada())
ps.setBoolean("condUser1", true);
Respuesta resp2 = respuestas.elementAt(1);
if (resp2.isSennalada())
ps.setBoolean("condUser2", true);
Respuesta resp3 = respuestas.elementAt(2);
if (resp3.isSennalada())
ps.setBoolean("condUser3", true);
return validacionOk;
Una vez configuradas estas condiciones, las mismas pueden ser utilizadas en la definicion de arbol a traves de los parametros $condUser1, $condUser2, $condUser3.
7.2 Include Information from Other Questions¶
7.2.1 Visualize Information¶
In some cases, you may want to display answers collected in previous steps within subsequent questions. This is possible by including programming instructions in the question tags. This functionality is available for the following question types:
-
Single option question: In the question tags, include the instruction
$encuesta.getPregunta("P1").getAnswerFromUser()where P1 is the identifier of the source question. -
Rate various options question: In the question tags, include the instruction
$encuesta.getPregunta("P1").getAnswerFromUser(n)where P1 is the source question identifier and n is the rating index. -
Matrix Numeric question: In the question tags, include the instruction
$encuesta.getPregunta("P1").getAnswerFromUserMatrixNumeric(n)where P1 is the source question identifier and n is the rating index. -
Text separator question.
-
Multiple Line Input Add question.
-
Values associated to Choice Attributes in both TickStat and personal models. These values are added in the same form where choice images are uploaded.
-
Matrix question: You can include response values from other questions in the matrix cells. Add the following variable in the footer of the target matrix question (include one entry per response in the target question):
Available variables:
$encuesta.getPregunta("P1").getAnswerFromUser()-- Returns the user's answer to question P1.$encuesta.getPregunta("P1").getLiteralAssociatedToAnswer()-- Returns the value set in the "Filter tab" field. This is only available for radio-type questions.$encuesta.getPregunta("P1").getPujaSelectedByUser()-- Where P1 is the parent question of a Simple Choice. Returns the bid presented to the user in the displayed child question.$encuesta.getPregunta("P1").getConfigMultipleInputSuma().getFormula()-- Where P1 is a Multiple Line Input Add question.$user.getGrupo().getAcumulatedFeeMoney()-- In game experiments, displays the final fee assigned to the user.$encuesta.getPregunta("P1").getItemsGeolocalizacion().get(0).getPoblacion()-- Returns the population of a point selected via the map-type question, or the name of the item selected in the map question's selection box. P1 is the map-type question.
In a choice question, the following variables can be used to include attribute values in the header:
$pregunta.getNumOrdenHija()-- Indicates the number of the card being presented.PROGRAMA CON PAGOS DURANTE $pregunta.getAttributeValue("durac 0") ANOS, PROGRAMA CON PAGOS DURANTE $pregunta.getAttributeValue("durac 1") ANOS, Programa Cdurac: The name of the attribute.0or1: The index of the alternative (first or second program).
If you need this functionality for a question type not listed above, please contact us.
7.2.2 Visualize Math Operations from Other Questions¶
You can use the $math function to insert values calculated through mathematical operations. The operands can be values from other questions or fixed numbers. Below are the available operators.
For example, to apply the following formula:
0.05 * $encuesta.getPregunta("P2").getAnswerFromUser() + $encuesta.getPregunta("P2").getAnswerFromUser()
Use the following syntax:
$math.add($math.mul(0.05, $encuesta.getPregunta("P2").getAnswerFromUser()), $encuesta.getPregunta("P2").getAnswerFromUser())
Detailed information about these operations can be found here: https://velocity.apache.org/tools/1.4/generic/MathTool.html
7.3 HTML Help¶
In some questions, you may want to apply formatting to the text in questions or answers. The tool provides an HTML code editor with syntax highlighting for editing rich content. This section provides templates to simplify this task.
Important: All HTML content should be wrapped in <div class="intro"> to use the styles from survey-intro.css. The older <div class="intro"> wrapper is deprecated but still supported for backwards compatibility.
7.3.1 Paragraph with unordered or ordered list¶
HTML code:
<div class="intro">
<p>Introductory paragraph for a list of options that will appear as bullets</p>
<ul>
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
<p>Please tell us what you think about this approach:</p>
</div>
7.3.2 Text with two horizontal images and captions¶
HTML code:
Note:
class="images"— setclass="images images_larger"to display larger images.
<div class="intro">
<p>Agriculture has great potential ...</p>
<div class="images">
<div class="row">
<div class="cell">
<img src="$contexto/img/$idEncuesta/y.jpg" />
<div class="legende">Current agriculture</div>
</div>
<div class="cell">
<img src="$contexto/img/$idEncuesta/x.jpg" />
<div class="legende">Agriculture with agri-environmental measures</div>
</div>
</div>
</div>
</div>
HTML for a single image, left-aligned:
<div class="images">
<div class="row">
<div class="cell justify-left">
<img src="img/EXAMPLE/co2_106.png">
</div>
</div>
</div>
7.3.3 Text with three horizontal images and captions¶
HTML code:
<div class="intro">
<p>
<strong>The creation or restoration of riparian forests</strong>
helps maintain rivers and streams in good ecological condition by retaining ...
</p>
<p>The following images show riparian forests of different widths.</p>
<div class="images">
<div class="row">
<div class="cell">
<img src="$contexto/img/$idEncuesta/BR1.jpg">
<div class="legende">caption 1</div>
</div>
<div class="cell">
<img src="$contexto/img/$idEncuesta/BR2.jpg">
<div class="legende">caption 2</div>
</div>
<div class="cell">
<img src="$contexto/img/$idEncuesta/BR3.jpg">
<div class="legende">caption 3</div>
</div>
</div>
<p>Which of the three do you prefer?</p>
</div>
</div>
7.3.4 Coloured callout boxes¶
<div class="intro">
<div class="alert alert-success my-3">
<ol>
<li>Proin at tortor at urna faucibus congue eu a sem.</li>
<li>Nam imperdiet nulla a turpis sodales, id venenatis dui lobortis.</li>
<li>Quisque nec orci vitae elit convallis volutpat.</li>
<li>Nulla efficitur metus quis lorem <strong>pueri</strong> consectetur.</li>
<li>Cras ac est vitae neque volutpat condimentum.</li>
<li>Donec accumsan velit eu consequat pellentesque.</li>
</ol>
</div>
<div class="alert alert-danger my-3">
<ol>
<li>Proin at tortor at urna congue eu a sem.</li>
<li>Nam imperdiet nulla a turpis sodales, id venenatis dui lobortis.</li>
<li>Quisque nec orci vitae elit convallis volutpat.</li>
<li>Nulla efficitur metus quis lorem consectetur.</li>
<li>Cras ac est vitae neque condimentum.</li>
<li>Donec accumsan velit eu consequat pellentesque.</li>
</ol>
</div>
</div>
7.3.5 Landing Question to Redirect User to Same Survey but in a Different Language¶
And here is the HTML to add to this question:
<div class="intro">
<p>Thank you for your interest in participating in this research...</p>
<div class="container">
<ul class="flag-gallery">
<li>
<a href="https://www.tickstat.com/surveys/visualize?code=SURVEY_CODE" target="_blank">
<img src="front/img/flags/4x3/es.svg" alt="" />
<div class="overlay"><span>Select Spanish</span></div>
</a>
</li>
<li>
<a href="https://www.tickstat.com/surveys/visualize?code=SURVEY_CODE" target="_blank">
<img src="front/img/flags/4x3/gb.svg" alt="" />
<div class="overlay"><span>Select English</span></div>
</a>
</li>
<!-- Add more languages as needed -->
</ul>
</div>
</div>
7.3.6 Glossary table¶
<div class="intro">
<div class="ts__flex ts__flex_col ts__center ts__w_100">
<div class="ts__table_container">
<table id="additive-manufacturing" class="ts__table">
<thead>
<tr class="ts_header_info">
<th colspan="2">Glossary of terms</th>
</tr>
<tr class="ts_header">
<th>Acronym</th>
<th>Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="ts__bold ts_center">FDM</td>
<td>Fused deposition modelling of plastic filaments</td>
</tr>
<tr>
<td class="ts__bold ts_center">SLA</td>
<td>Stereolithography (curing of plastic resins)</td>
</tr>
<!-- Add more rows as needed -->
</tbody>
</table>
<div class="ts__table_info ts__text_center">
<span class="ts__info_label ts__bold">Table caption</span>
</div>
</div>
</div>
</div>
7.3.7 Implicit Association Test (IAT) — instructions snippet¶
For the introduction screen of an IAT block, include an HTML snippet such as the following (translate as needed for your respondent population):
<div class="info_title ts_bold">Bird perception survey</div>
<p>
On the next screen, we will show you images of <b>birds</b>
that you must classify into one of the categories shown
at the top left and top right of the screen. It is essential
that you classify the images as quickly as possible. If you
take the test too slowly, the result will not be valid.
</p>
<p>
The categories appear at the top of the screen, on the left
and on the right. The images will appear in the centre of
the screen.
</p>
<p>
Press the <b>E</b> key to classify the image into the
left-hand category, and press the <b>I</b> key to classify
it into the right-hand category.
</p>
<p>
The test will not return a valid result if you respond too
slowly, so try to go as fast as you can. We recommend
placing your index fingers on the E and I keys before
starting.
</p>
<p>
For best results, avoid distractions and stay focused.
Press the spacebar to begin.
</p>
7.3.8 Matrix Header¶
Below is an example of a matrix header with links: