Getting started with the Evaluation Options Editor API

This article shows you how to add the Evaluation Options Editor to your page, load existing options, and read the options that an author sets.

1. Include the script to load Evaluation Options Editor API

Include the following script in your HTML page, and also a DOM node where you want the editor UI to appear.

<script src="https://feedbackaide.learnosity.com/js/evaluation-options-editor"></script>
...
<div class="evaluation-options-editor-container"></div>

Code example: Loading the Evaluation Options Editor API script and adding a container for the editor.

This script adds a LearnosityEvaluationOptionsEditor object to the JavaScript runtime. Run the code in the following steps inside an async function or a <script type="module"> element.

2. Create an instance of the app with LearnosityEvaluationOptionsEditor.init()

In the JavaScript code of your app, create an instance of the Evaluation Options Editor app.

const evaluationOptionsEditorApp = await LearnosityEvaluationOptionsEditor.init();

Code example: Creating an instance of the Evaluation Options Editor app.

3. Create the editor instance using createEditor()

Call createEditor() to create an editor. The following example creates an editor that opens in a dialog and loads existing options.

const editor = await evaluationOptionsEditorApp.createEditor({
    variant: "modal",// Opens the editor in a dialog
    options_json: { grading: { marking_style: "harsh" } } // Optional: existing options to load into the editor
});

Code example: Creating an editor that opens in a dialog and loads existing options.

To start with no options set, omit options_json. The editor shows the default value for every option that is not in the JSON. For the format of the options and their default values, see evaluation options.

4. Attach the editor to the page

Call attach() with the container element you added in step 1.

await editor.attach(document.querySelector(".evaluation-options-editor-container"));

Code example: Attaching the editor to the container.

The modal variant renders an Evaluation options button in the container. Selecting the button opens the editor in a dialog. The default variant renders the editor directly in the container.

The modal variant, with the Evaluation options button and the editor in its dialog..png
The modal variant, with the Evaluation options button and the editor in its dialog.

5. Read the options

Listen for the change event to get the options each time they change.

editor.on("change", function (options) {
    console.log("options changed", options);
});

Code example: Logging the options each time they change.

When the change event fires depends on the variant:

  • In the modal variant, it fires when the author selects Confirm Options.
  • In the default variant, it fires as the author edits.

To read the current options at any time, call await editor.getOptions(). It returns null when no options are set, so check for null before you use the result.

Pass the options to Feedback Aide API as the options of your feedback session. For more information, see evaluation options.

Next steps

The Evaluation Options Editor API includes a range of configurable options, for example, to hide tabs of options from your authors. See the Evaluation Options Editor API Developer Documentation.

To choose how the editor is displayed, see Customizing the Evaluation Options Editor UI using variants.

Was this article helpful?

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