This is a lower-level API. Lower-level APIs are not recommended for most projects, and may not be available on all plans. See our page on recommended deployment patterns for more information.
Public Method Question Editor API

setWidget()

Sets JSON to edit in the Question Editor API. The Question Editor API will open the specified question/feature type and pre-populate attributes from the supplied JSON.

The responseJson argument is the JSON Object to set in the editor for editing.

setWidget accepts an object specifying a template_reference key for the template as a second argument. If this is set, the widget is displayed within the template specified by the argument. Use that approach if you have custom template (with hidden sections, fields, etc.) set up as reference of QuestionType inside question_types.

Important: This method should only be called once the Question Editor API is fully loaded. It is provided to allow setting JSON at later stages if needed. If you have not loaded the Question Editor API and want to initialise the API with a specific question/feature type and pre-filled data, you should use the widget_json init option rather than setWidget.

Note User must have called undo method before being able to call redo method.

Examples

// on clicking the setWidget button, provide the new Response object with a changed picture.
    var responseJson = {
        "type": "highlight",
        "description": "The student needs to mark one of the flower's anthers in the image.",
        "img_src": "http://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Mono_Lake_Old_Marina_August_2013_012.jpg/320px-Mono_Lake_Old_Marina_August_2013_012.jpg",
        "line_color": "rgb(255, 20, 0)",
        "line_width": "4"
    };

    document.getElementById('setWidget').onclick = function (){
        questionEditorApp.setWidget(
            responseJson,
            {
                "template_reference": "908de244-5c71-4c09-b094-7fb49554f2f9"
            }
        );
    };

Arguments

  • widget_json object

    The widget JSON to be set

  • widget_template object

    The widget template to be used to render JSON. Template of same question/feature type is supported that is determined by widget_json, otherwise default template is used

    Default: First template available for question/feature type

Return value

None (undefined).

Was this article helpful?