smccartney09
05-01-2024Cloud Apps
Status:
Needs Votes & Comments
Ability to add key/value metadata to widgets
My team was adding scripts to widgets to add attributes to the embedded widget and noticed an opportunity to expand what metadata we can use in the scripts. Currently, we're using the widget description (`desc` field) to set a testid attribute, but by default that description is viewable in the embedded widget.
I'd love the ability for designers to add key/value pairs to the Widget class metadata that are accessible in the widget script.
widget.on('domready', function(w) {
const { oid, customMetadata } = w; // customMetadata is the new (optional) property on a Widget
const testId = customMetadata['testId']; // a key/value pair added by designer
const selectorString = `[widgetid='${oid}']`;
const widgetElement = $(selectorString);
widgetElement[0].setAttribute('testid', testId);
});