attribute - Methods - Question Editor API

Question Editor API Methods


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.



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


  • attribute_path string

Return value

Type attributeObject

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

  • 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

    • value string

      Value of attribute object

Type 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();
Was this article helpful?

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