setOptions - Methods - Evaluation Options Editor API

Evaluation Options Editor API Methods

setOptions()

Loads the specified evaluation options into the editor.

You would want to use this method so that you can display options you saved earlier, for example, when the author switches to another Question.

The loaded options replace all the options that are currently set, and the editor shows the default value for every option that is not in the JSON. You can call this method before you attach the editor or while it is detached.

Examples

// Load options and suppress the change event for this call
await editor.setOptions(
    {
        grading: {
            learner_level: 'academic-5'
        }
    },
    { silent: true }
);

Arguments

  • options object

    The evaluation options object to load into the editor. For the format, see evaluation options.

  • settings object

    Controls optional settings for how the options are loaded.

    The following properties are supported.

    • silent boolean

      Controls whether the change event is fired.

      You would want to use this argument to load options without triggering the change event.

      Default: false

    • strict boolean

      Controls whether the options are validated against the evaluation options schema.

      You would want to set this argument to false when you need to load options that contain values the schema does not allow, for example, options that you saved with an earlier version.

      Default: true

      Possible values

      • true - The editor validates the options against the schema and rejects them if a value is not allowed.
      • false - The editor does not validate the options.

Return value

Type Promise

Resolves when the options are loaded, or rejects if the options are invalid.

Caveats

  • This method fires the change event unless you set silent to true. If you call this method from a change event handler, set silent to true to avoid an infinite loop.
  • When the editor is attached with the default variant, it can fire the change event again shortly after this method resolves, when it displays the loaded options. This can happen even when silent is true.
Was this article helpful?

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