setWidget - Methods - Question Editor API

Question Editor API Methods


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.


// 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": "",
        "line_color": "rgb(255, 20, 0)",
        "line_width": "4"

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


  • 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?

Did you arrive here by accident? If so, learn more about Learnosity.