The Survey

Rationale

To avoid the continuos editing of a verbose HTML file, the survey structure has been parametrized. This allows to edit freely the survey without editing the HTML file, and for this reason assures a consistent look to all the survey’s questions.

For this, a basic schema of the survey data has been defined. Note that this schema is in no way enforced: there’s no checking of your data and any properties not defined in this schema won’t raise any error but will be ignored. On the other side, any defined and required property that’s not defined in the configuration object could block the HTML generation or (in the worst case) generate a wrong HTML structure.

The Schema

The survey is generated using the exported object defined in the module survey-data.js. Here is documented the structure of that object.

class Survey()

The survey configuration object.

Arguments
  • introduction (string) – The introduction to the survey. Treated as raw HTML.

  • sections (Array.<Section>) – The survey’s sections.

class Section()

A section of the survey.

Arguments
  • title (string) – The section’s title.

  • questions (Array.<Question>) – The section’s questions.

class Question()

A question of the survey. @extends BasicQuestion.

Arguments
  • type (string) – The type of question.

  • rules (Object) – Various additional rules. Can be any HTML attribute accepted by the current input type.

  • placeholder (string) – The input placeholder.

  • choices (Array.<ChoiceDescription>|number) – A list of choices. Used only if type is ‘choice’ or ‘radios’. If it’s a number n, it’s used to generate n ChoiceDescription objects having {label: i, value: i}, con 1 <= i <= n.

  • question (string|Array.<BasicQuestion>) – If it’s a string, the same as BasicQuestion.question. If an array of BasicQuestion, a list of questions used if type is ‘likert’.

class BasicQuestion()

A basic question of the survey. This class contains all the required field of a question.

Arguments
  • question (string) – The question that will be asked to the user.

  • name (string) – The name of the GET/POST parameter.

  • required (boolean) – Wether or not the input is required.

class ChoiceDescription()

A description of a Question choice.

Arguments
  • label (string) – The label of the choice. This will be seen by the user.

  • value (any) – The value of the choice. This will be sent to the server.