Skip to content

Elements

guilhermeneugenio edited this page Nov 4, 2020 · 48 revisions

Elements

In this page is explained how to use each element in the json file that defines the form. Each of these elements can be added to the elements array mentioned in the README.

All the available elements must have the type field which must take the value one of the values exemplified bellow. The name field is also required and common to all the elements, it must be a string that will be displayed above the input of each element in the form. All the answers to every element contain an type field that has the same value of the one in the question(element) that originated that answer.

Core Elements (SurveyJS compatible)

In the Core Elements can found all the elements that are obtainable when creating a JSON form using SurveyJS. The JSON for these elements follows the exact syntax used by the SurveyJS tool.

Boolean

Switch button that can take the value of true(switch ON) or false(switch OFF). The labelTrue and labelFalse props are not used, they are just there for a compatibility issue with SurveyJS.

Usage

{
    "type": "boolean",
    "name": "boolean title",
    "labelTrue": "Yes",
    "labelFalse": "No"
}

Answer

The value field in the answer can be true or false depending on the user's answer.

{
    "type": "boolean",
    "value": {"true", "false"}
}

Checkbox

List of options that can be selected/unselected on press. State is shown with a checkbox icon. The choices array contains the items to be displayed in the list. The icon field allows to choose between squarered or circular checkboxes (defaults to circle).

Usage

{
    "type": "checkbox",
    "name": "checkbox title",
    "choices": [
        "item1",
        "item2",
        "item3",
        ...
    ],
    "icon": {"square", "circle"}
}

Answer

The value field contains an array with the selected options, the array elements can only be a combinations of the ones in the choices array mentioned before.

{
    "type": "checkbox",
    "value": [
        "item2",
        ...
    ]
}

Comment

Text box where the user can leave a comment up to 240 characters. This element is ideal for larger text inputs.

Usage

{
    "type": "comment",
    "name": "comment title"
}

Answer

The answer's value holds the text inserted by the user.

{
    "type": "comment",
    "value": "This is a test comment."
}

Dropdown

Allows user to select one single output in a dropdown menu of choices.

Usage

{
    "type": "dropdown",
    "name": "dropdown title",
    "choices": [
        "item1",
        "item2",
        "item3",
        ...
    ]
}

Answer

The value field contains the option selected from the question choices array via the dropdown.

{
    "type": "dropdown",
    "value": "item3"
}

Expression

A read-only component to deploy an expression to the user.

Usage

{
    "type": "expression",
    "name": "expression title",
    "commentText": "Other (describe)"
}

This element does not produce an answer.

File

This element allows the user to pick and upload a file from its device. This file will encoded in base64 and sent as part of the answer to the survey. The maxSize prop is used to set a maximum size of the selected files, in the current version this is functionality is not implemented.

Usage

{
    "type": "file",
    "name": "file title",
    "maxSize": 0
}

Answer

The answer's value field will have the base64 file data.

{
    "type": "file",
    "value": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyBy..."
}

Html

Form element that displays the code html code received through the html field. In the form page this element will render a display area with a limited height, it is possible to expand the display area by clicking on it. Allow the user to visualize the entire html if the default height is not enought to do so. The might be some issues with font size of the displayed html, this can be solve by adding to the html code the head with the meta showed below.

Usage

{
    "type": "html",
    "name": "question10",
    "html": "<html><head><meta name='viewport' content='width=device-width, initial-scale=1'></head><body><div><p>Html Element</p></div></body></html>"
}

This element does not produce an answer.

Image

Form element that displays an Image to the user, having an imageLink prop containing the link of the image to be rendered. The image is rendered with its original size (width and height).

Usage

{
    "type": "image",
    "name": "image title",
    "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg"
}

This element does not produce an answer.

Image Picker

Allows user to select image(s) displayed in a grid. Each image has a imageLink prop containing the link of the image to be rendered, having a value associated with it. All the images displayed in the grid are grouped inside the choices array. Optionally, there is 3 customization fields to this element: numberPerLine that determines the number of images per line, imageSize that defines the size of the images to be displayed ("small", "medium" or "big") and singleChoice, a boolean value that allows multiple choices or not.

Usage

{
    "type": "imagepicker",
    "name": "imagepicker title",

    "numberPerLine": 2,
    "imageSize": "medium",
    "singleChoice": true,

    "choices": [
        {
            "value": "lion",
            "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg"
        },
        {
            "value": "giraffe",
            "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/giraffe.jpg"
        },
        ...
    ]
}

Answer

The answer will have an array in the value field containing the values associated with the picked images.

{
    "type": "imagepicker",
    "value": [
        "lion",
        "giraffe",
        ...
    ]
}

Matrix Dropdown

Form element displayed as a matrix that allows user to choose a value from the choices prop for each column and row with a dropdown menu system.

Usage

{
    "type": "matrixdropdown",
    "name": "matrixdropdown title",
    "columns": [
        {
            "name": "Column 1"
        },
        {
            "name": "Column 2"
        },
        ...
    ],
    "choices": [
        1,
        2,
        3,
        ...
    ],
    "rows": [
        "Row 1",
        "Row 2",
        ...
    ]
}

Answer

The answer's value is an array where each of its elements is another array with the values selected for each columns of a certain row.

{
    "type": "matrixdropdown",
    "value": [
        [
            {
                "column": "Column 1",
                "row": "Row 1",
                "value": 1
            },
            {
                "column": "Column 2",
                "row": "Row 1",
                "value": 2
            },
            ...
        ],
        [
            {
                "column": "Column 1",
                "row": "Row 2",
                "value": 5
            },
            {
                "column": "Column 2",
                "row": "Row 2",
                "value": 4
            },
            ...
        ],
        ...
    ]
}

Matrix Dynamic [Not yet Implemented]

Usage

{
    "type": "matrixdynamic",
    "name": "matrixdynamic title",
    "columns": [
        {
            "name": "Column 1"
        },
        {
            "name": "Column 2"
        },
        ...
    ],
    "choices": [
        1,
        2,
        3,
        ...
    ]
}

Answer

Matrix

Form element that displays a matrix that allows user to choose a column for each row with a radio buttons system.

Usage

{
    "type": "matrix",
    "name": "matrix title",
    "columns": [
        "Column 1",
        "Column 2",
        "Column 3",
        ...
    ],
    "rows": [
        "Row 1",
        "Row 2",
        ...
    ]
}

Answer

In the answer can be found an array containing objects with the combination of rows and columns selected by the user.

{
    "type": "matrix",
    "value": [
        {
            "column": "Column 1",
            "row": "Row 1"
        },
        {
            "column": "Column 2",
            "row": "Row 2"
        },
        ...
    ]
}

Multiple Text

Provides multiple simple text input box, allowing the user to submit text data for each displayed box. Each simple text input have a maximum number of 40 characters.

Usage

{
    "type": "multipletext",
    "name": "multipletext title",
    "items": [
        {
            "name": "text1"
        },
        {
            "name": "text2"
        },
        ...
    ]
}

Answer

The answer's value is an array of objects, where is object has a name corresponding to the title given to the input field of the form and a value with the text inserted by the user.

{
    "type": "multipletext",
    "value": [
        {
            "name": "text1",
            "value": "teste 1"
        },
        {
            "name": "text2",
            "value": "teste 2"
        },
        ...
    ]
}

Panel Dynamic [Not yet Implemented]

Usage

{
    "type": "paneldynamic",
    "name": "paneldynamic title"
}

Answer

Panel [Not yet Implemented]

Usage

{
    "type": "panel",
    "name": "panel title"
}

Answer

Radio

Provides choices to the user in a Radio choice system, having a single output after submission.

Usage

{
    "type": "radiogroup",
    "name": "radio title",
    "choices": [
        "item1",
        "item2",
        "item3"
    ]
}

Answer

The value field will have one of the options from the choices array mention previously.

{
    "type": "radiogroup",
    "value": "item3"
}

Rating

Allows user to evaluate in a 0 to 5 star rating system. The element uses star icons to represent the classification instead of numbers.

Usage

{
    "type": "rating",
    "name": "rating title"
}

Answer

The answer's value contains the rating value given by the user.

{
    "type": "rating",
    "value": 4
}

Text

Provides a simple text input box, allowing the user to submit text data up to 40 characters.

Usage

{
    "type": "text",
    "name": "text title"
}

Answer

The answer's values field holds the inputed text.

{
    "type": "text",
    "value": "text input data"
}

Extra Elements

The Extra Elements are not comprised by the SurveyJS tool but where developed to provide more options to the users of this package.

Camera

This element allow the user to take a pictures using the device's camera, the taken photo is then previewed in the form page. When the form is submit the photo data is collected in base64.

Usage

{
    "type": "camera",
    "name": "Camera Title"
}

Answer

{
    "type": "camera",
    "value": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyBy..."
}

Date Picker

Allows user to pick a specific date. The mode prop allows to pick it manually(manual) or to automatically(auto) select the current date.

Usage

{
    "type": "datepicker",
    "name": "Datepicker Title",
    "mode": {"auto, "manual"}
}

Answer

The value field in the answer holds the date collected by the component in a dd:mm:yyyy format.

{
    "type": "datepicker",
    "value": "26-7-2020",
}

Time Picker

Allows user to pick a specific time. The mode prop allows to pick it manually(manual) or to automatically(auto) select the current time.

Usage

{
    "type": "timepicker",
    "name": "Timepicker Title",
    "mode": {"auto, "manual"}
}

Answer

The value field in the answer holds the time collected by the component in a hh:mm:ss format.

{
    "type": "timepicker",
    "value": "14:19:30"
}

Range

Slider bar that will allow the user to choose a value between min and max with a precision of step, being this last one set to 1 by default if not defined by user.

Usage

{
    "type": "range",
    "name": "Range Title",
    "min": 0,
    "max": 200,
    "step": 1
}

Answer

The answer will have a value field with the value selected using the slider bar.

{
    "type": "range",
    "value": 124,
}