Question Editor API Methods
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 do not want to change anything else, use this 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
Type attributeObject
A returned object instance, for example, stimulus.
-
addArrayItem function
To add a new Item to array collection type attribute, for example, options, stems, response_containers.
The following arguments are available.
-
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
The following arguments are available.
-
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();