Create a util function for validating data attribute requirements based on templateId
In some cases we have templates which require more data than others. It can be difficult to know which template requires what data for certain widgets (ex. Newsroom Resources) at a glance. Sometimes it may seem to work (because no errors were thrown) but will lead to bugs.
Possible Solution
I'm thinking we should throw errors when an attribute is required and not provided by the user.
We can define an object at the top of our widget js files:
const requiredOptionsForTemplates = {
default: {
resTitle: true,
resType: true,
resViewMore: false
},
image: {
resTitle: false
}
};
The default
property will be used for all templates unless otherwise specified. For the example above, all templates will require resTitle
except the template with a templateId
of image
.
and have a util function which will throw an error if a property in requiredOptionsForTemplates[templateId]
is true
but the data attribute is undefined
or null
.