questions package

Submodules

Module contents

Top-level package for Questions.

class questions.BarRatingQuestion(**data)[source]

Bases: DropdownQuestion

A question that uses the JQuery bar rating widget.

extra_css: List[HttpUrl]
extra_js: List[HttpUrl]
kind: str
rating_theme: Literal['fontawesome-stars', 'css-stars', 'bars-pill', 'bars-1to10', 'bars-movie', 'bars-reversed', 'bars-horizontal', 'fontawesome-stars-o']
show_values: bool
class questions.BooleanQuestion(**data)[source]

Bases: Question

Get the answer for any two-possibility question. Usually true/false, yes/ no questions.

kind: str
label_false: Union[str, Dict[str, str]]
label_true: Union[str, Dict[str, str]]
show_title: bool
value_false: Union[str, Dict[str, str]]
value_true: Union[str, Dict[str, str]]
class questions.BootstrapDatePickerQuestion(**data)[source]

Bases: TextQuestion

A question that uses the bootstrap date picker.

auto_close: bool
clear_button: bool
date_format: str
days_of_week_highlighted: str
disable_touch_keyboard: bool
end_date: str
extra_css: List[HttpUrl]
extra_js: List[HttpUrl]
kind: str
start_date: str
today_highlight: bool
week_start: int
class questions.BootstrapSliderQuestion(**data)[source]

Bases: Question

A question that uses the bootstrap slider widget.

extra_css: List[HttpUrl]
extra_js: List[HttpUrl]
kind: str
range_max: int
range_min: int
step: int
class questions.CKEditorQuestion(**data)[source]

Bases: Question

A question that uses the CKEditor JQuery widget.

extra_js: List[HttpUrl]
height: str
kind: str
class questions.CheckboxQuestion(**data)[source]

Bases: ChoicesQuestion

Select one or more options from a group of check boxes.

has_none: bool
has_select_all: bool
kind: str
none_text: Union[str, Dict[str, str]]
select_all_text: Union[str, Dict[str, str]]
class questions.CommentQuestion(**data)[source]

Bases: Question

A question that uses a text area to get a multi-line text answer.

cols: int
kind: str
max_length: int
place_holder: Union[str, Dict[str, str]]
rows: int
text_update_mode: Literal['default', 'onBlur', 'onTyping']
class questions.DropdownQuestion(**data)[source]

Bases: ChoicesQuestion

Select one option from a dropdown menu.

choices_max: int
choices_min: int
choices_step: int
kind: str
options_caption: str
show_options_caption: bool
class questions.EmailValidator(**data)[source]

Bases: Validator

Checks if a value is a valid email address.

kind: str
class questions.EmotionsRatingQuestion(**data)[source]

Bases: DropdownQuestion

A question that uses the emotion ratings JQuery widget.

bg_emotion: str
emotion_color: str
emotion_size: int
emotions: List[str]
emotions_count: int
extra_js: List[HttpUrl]
kind: str
class questions.ExpressionBlock(**data)[source]

Bases: Question

A block that inserts the result of an expression in a form.

currency: str
display_style: Literal['none', 'decimal', 'currency', 'percent', 'date']
expression: str
expression_format: str
kind: str
maximum_fraction_digits: int
minimum_fraction_digits: int
use_grouping: bool
class questions.ExpressionValidator(**data)[source]

Bases: Validator

Checks if a question’s answer matches a set of conditions.

expression: str
kind: str
class questions.FileQuestion(**data)[source]

Bases: Question

A question for uploading one or more files.

accepted_types: str
allow_images_preview: bool
allow_multiple: bool
image_height: int
image_width: int
kind: str
max_size: int
need_confirm_remove_file: bool
show_preview: bool
store_data_as_text: bool
wait_for_upload: bool
class questions.Form(name='', action='', html_id='questions_form', theme='defaultV2', platform='jquery', resource_url=None, **params)[source]

Bases: object

This is the base class used for creating user-defined forms. In addition to setting up the form configuration and performing validation, it generates the SurveyJS form JSON and keeps track of the required Javascript and CSS resources.

Parameters:
  • name (str) – The name of the form. If empty, the class name is used.

  • action (str) – The URL where the form data will be posted. If empty, the same URL for the form is used.

  • html_id (str) – The id for the div element that will be used to render the form.

  • theme (Literal['defaultV2', 'bootstrap', 'modern']) – The name of the base theme for the form. Default value is ‘defaultV2’.

  • platform (Literal['angular', 'jquery', 'knockout', 'react', 'vue']) – The JS platform to use for generating the form. Default value is ‘jquery’.

  • resource_url (Optional[str]) – The base URL for the theme resources. If provided, Questions will expect to find all resources under this URL. If empty, the SurveyJS CDN will be used for all resources.

  • params – Optional list of parameters to be passed to the SurveyJS form object.

property css

Combined CSS resources for this form.

default_params = {}
property extra_css

Any extra CSS resources required by the form’s question types.

property extra_js

Any extra JS resources required by the form’s question types.

classmethod from_json(form_json, name)[source]

Generate a Form class definition from properly formatted JSON data. The The generated form class can then be instantiated as needed.

Parameters:
  • form_json (str) – A well formed JSON string with a SurveyJS definition.

  • name (str) – The name of the generated class.

Returns:

A new Python Type that is a subclass of Form.

property js

Combined JS resources for this form.

questions_resource_url = 'https://unpkg.com'
render_html(title=None, form_data=None)[source]

Render a full HTML page showing this form.

Parameters:
  • title (Optional[str]) – The form title.

  • form_data (Optional[Dict[str, Any]]) – answers to show on the form for each question (for edit forms).

Returns:

String with the generated HTML.

render_js(form_data=None)[source]

Generate the SurveyJS initialization code for the chosen platform.

Parameters:

form_data (Optional[Dict[str, Any]]) – answers to show on the form for each question (for edit forms).

Returns:

String with the generated javascript.

property required_css

Required CSS resources needed to run SurveyJS on chosen platform.

property required_js

Required JS resources needed to run SurveyJS on chosen platform.

classmethod set_resource_url(url)[source]
to_json()[source]

Convert the form to JSON, in the SurveyJS format.

Returns:

JSON object with the form definition.

update_object(obj, form_data)[source]

Utility method to set an object’s attributes with data obtained from a form. This method validates the data before setting the object’s attributes.

Parameters:
  • obj (Any) – The object to set attributes on.

  • form_data (Dict[str, Any]) – A dictionary-like object with the form data to be validated.

Raises:

questions.validators.ValidationError if validation does not pass.

validate(form_data, set_errors=False)[source]

Server side validation mimics what client side validation should do. This means that any validation errors here are due to form data being sent from outside the SurveyJS form, possibly by directly posting the data to the form. Questions keeps track of the errors, even though the UI will show them anyway. Validation returns False if at least one validator doesn’t pass.

Parameters:
  • form_data (Dict[str, Any]) – A dictionary-like object with the form data to be validated.

  • set_errors (bool) – set to True to add an __errors__ key to the form data dictionary, containing the validation errors.

Returns:

True if the validation passes, False otherwise.

class questions.FormPage(form, name='', **params)[source]

Bases: object

Represents an individual page from a multi-page form.

Parameters:
  • form (Type[Form]) – A subclass of questions.Form (not an instance). The form to be shown in its own page.

  • name (str) – The name of the form.

  • params – Optional list of parameters to be passed to the SurveyJS page object.

class questions.FormPanel(form, name='', dynamic=False, **params)[source]

Bases: object

A panel is a set of fields that go together. It can be used for visual separation, or as a dynamically added group of fields for complex questions.

Parameters:
  • form (Type[Form]) – A subclass of questions.Form (not an instance). The form to be shown in its own page.

  • name (str) – The name of the form.

  • dynamic (bool) –

    Set to True if the panel will be used as a template for adding

    or removing groups of questions.

  • params – Optional list of parameters to be passed to the SurveyJS panel object.

class questions.HtmlBlock(**data)[source]

Bases: Question

An HTML block that can be embedded in a form.

html: Union[str, Dict[str, str]]
kind: str
class questions.ImageBlock(**data)[source]

Bases: Question

An block for inserting an image in a form.

content_mode: Literal['image', 'video']
image_fit: Literal['contain', 'none', 'cover', 'fill']
image_height: int
image_width: int
kind: str
class questions.ImagePickerQuestion(**data)[source]

Bases: ChoicesQuestion

Display a group of images and let the user pick one or more.

content_mode: Literal['image', 'video']
has_other: bool
image_fit: Literal['contain', 'none', 'cover', 'fill']
image_height: int
image_width: int
kind: str
multi_select: bool
other_error_text: Union[str, Dict[str, str]]
other_place_holder: Union[str, Dict[str, str]]
other_text: Union[str, Dict[str, str]]
show_label: bool
class questions.JQueryUIDatePickerQuestion(**data)[source]

Bases: TextQuestion

A question that uses the JQueryUI date picker.

config: str
date_format: str
extra_css: List[HttpUrl]
extra_js: List[HttpUrl]
kind: str
max_date: str
min_date: str
class questions.MatrixDropdownQuestion(**data)[source]

Bases: Question

A matrix question that can include other types of input controls, like dropdowns and text boxes.

all_rows_required: bool
cell_type: Literal['dropdown', 'checkbox', 'radiogroup', 'text', 'comment', 'boolean', 'expression', 'rating']
cells: Dict[str, Dict[str, Any]]
choices: List[Any]
column_col_count: int
column_layout: Literal['horizontal', 'vertical']
column_min_width: str
columns: List[Any]
columns_visible_if: str
horizontal_scroll: bool
kind: str
options_caption: str
row_title_width: str
rows: List[Any]
rows_order: Literal['initial', 'random']
rows_visible_if: str
show_header: bool
total_text: str
class questions.MatrixDynamicQuestion(**data)[source]

Bases: Question

A matrix dropdown question that allows the user to add or remove new rows from their answer.

add_row_location: Literal['default', 'top', 'bottom', 'topBottom']
add_row_text: str
all_rows_required: bool
allow_add_rows: bool
allow_remove_rows: bool
cell_type: Literal['dropdown', 'checkbox', 'radiogroup', 'text', 'comment', 'boolean', 'expression', 'rating']
cells: Dict[str, Dict[str, Any]]
choices: List[Any]
column_col_count: int
column_layout: Literal['horizontal', 'vertical']
column_min_width: str
columns: List[Any]
columns_visible_if: str
confirm_delete: bool
confirm_delete_text: str
default_row_value: Any
default_value_from_last_row: bool
horizontal_scroll: bool
key_duplication_error: str
key_name: str
kind: str
max_row_count: int
min_row_count: int
options_caption: str
remove_row_text: str
row_count: int
rows: List[Any]
rows_order: Literal['initial', 'random']
rows_visible_if: str
show_header: bool
class questions.MatrixQuestion(**data)[source]

Bases: Question

A question that displays rows of radio buttons and allows the user to select a value from one of several columns for each row.

all_rows_required: bool
cells: Dict[str, Dict[str, str]]
columns: List[Any]
columns_visible_if: str
kind: str
rows: List[Any]
rows_order: Literal['initial', 'random']
rows_visible_if: str
show_header: bool
class questions.MicrophoneQuestion(**data)[source]

Bases: Question

A question that uses the RecordRTC sound recording widgets.

extra_js: List[HttpUrl]
kind: str
class questions.MultipleTextQuestion(**data)[source]

Bases: Question

A text question with multiple related parts. Displays a text box for each part.

col_count: int
item_size: int
items: List[Dict[str, str]]
kind: str
class questions.NoUISliderQuestion(**data)[source]

Bases: Question

A question that uses the NoUISlider JQuery widget.

direction: str
extra_css: List[HttpUrl]
extra_js: List[HttpUrl]
kind: str
orientation: str
pips_density: int
pips_mode: str
pips_text: List[Union[int, str]]
pips_values: List[int]
range_max: int
range_min: int
step: int
tooltips: bool
class questions.NumericValidator(**data)[source]

Bases: Validator

Validator for numeric input.

kind: str
max_value: int
min_value: int
class questions.RadioGroupQuestion(**data)[source]

Bases: ChoicesQuestion

Select one option from a group of radio buttons.

kind: str
show_clear_button: bool
class questions.RatingQuestion(**data)[source]

Bases: Question

A question that lets the user select a number on a fixed scale.

kind: str
max_rate_description: Union[str, Dict[str, str]]
min_rate_description: Union[str, Dict[str, str]]
rate_max: int
rate_min: int
rate_step: int
rate_values: List[Union[int, Dict[str, Union[int, str]]]]
class questions.RegexValidator(**data)[source]

Bases: Validator

Checks if a value matches a regular expression.

kind: str
regex: str
class questions.Select2Question(**data)[source]

Bases: DropdownQuestion

A question that uses the Select2 dropdown widget.

extra_css: List[HttpUrl]
extra_js: List[HttpUrl]
render_as: str
select2_config: str
class questions.SignaturePadQuestion(**data)[source]

Bases: Question

Allow the user to “sign” something by drawing their signature. Can be used to capture user drawings for other types of questions.

allow_clear: bool
height: int
kind: str
width: int
class questions.SortableJSQuestion(**data)[source]

Bases: CheckboxQuestion

A question that uses the JQuery sortable widget.

empty_text: str
extra_js: List[HttpUrl]
kind: str
max_answers_count: int
class questions.TagBoxQuestion(**data)[source]

Bases: DropdownQuestion

A question that uses the Select2 tag box widget.

extra_css: List[HttpUrl]
extra_js: List[HttpUrl]
kind: str
select2_config: str
class questions.TextQuestion(**data)[source]

Bases: Question

A question that uses a text input box. It can handle all HTML5 text input types.

auto_unmask: bool
extra_js: List[HttpUrl]
input_format: str
input_mask: str
input_type: Literal['color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'number', 'password', 'range', 'tel', 'text', 'time', 'url', 'week']
kind: str
max_length: int
max_value: str
min_value: str
place_holder: Union[str, Dict[str, str]]
prefix: str
size: int
step: str
text_update_mode: Literal['default', 'onBlur', 'onTyping']
class questions.TextValidator(**data)[source]

Bases: Validator

Validator for text input.

allow_digits: bool
kind: str
max_length: int
min_length: int
exception questions.ValidationError[source]

Bases: Exception

Validation error exception, for use by Form.update_object.