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

attribute()

Allows you to get, modify, or remove a specified input value based on an attribute path.

For example, if you wanted to set the stimulus but didn't want to change anything else, it would be better to use the attribute method rather than setWidget.

Examples

questionEditorApp.attribute("stimulus");

/* example output - returns object with available functions
{
    {getValue: f, setValue: f, remove: f}
}
*/

Arguments

  • attribute_path string

Return value

  • attributeObject object

    A returned instance of attribute e.g. stimulus.

    Properties
    function

    To add a new item to array collection type attribute
    e.g. options, stems, response_containers

    function

    Get current value of given attribute

    Returns: string
    function

    To remove given array item, available for node of array collection only
    e.g. options[1], stems[0]

    function

    Set value of given attribute

    Returns: attributeObject
  • undefined
    If the attribute does not exist. This could happen with custom questions for example.

    For this reason, make sure to check the returned value is a defined object before calling its methods.

    One way of doing this is by leveraging optional chaining for example with

    const value = attribute('stimulus')?.getValue();

Type definitions

attributeObject object

A returned instance of attribute e.g. stimulus.

  • addArrayItem function

    To add a new item to array collection type attribute
    e.g. options, stems, response_containers

    • array_item string

      New array item

  • getValue function

    Get current value of given attribute

    Returns: string
  • remove function

    To remove given array item, available for node of array collection only
    e.g. options[1], stems[0]

  • setValue function

    Set value of given attribute

    Returns: attributeObject
    • value string

      Value of attribute object

Was this article helpful?