Hey! I am probably just doing something goofy here, but I can’t seem to get custom plugins to work for math operations.
(I know I can just make it happen in JS, but I’m trying to learn how to take advantage of the builder’s features because, as you know since you built the thing, it would make it a lot more convenient .)
I’m trying to build “Next” and “Previous” buttons. I’ve set it up so that my url has both a routing variable and a query parameter for the week number I want to fetch (e.g. if I click on the “4” button, it gets me values filtered to only include week 4, the end of the url for which is ‘/4?week=4’).
I tried making a plugin that seems to work in preview, but not in execution (it comes up as ‘null’ when I try to click the “Next” button).
The plugin takes one parameter (‘add’), which I’m intending to be the number I want to add to the base ‘value’.
Here’s the plugin code:
mdFunctions.OnReady(() =>
{
mdFunctions.ItemAdd({
id: 'add',
parameters: {
add: {type: 'INPUT'},
},
description: 'Performs addition.',
group: 'String',
function: function(data, value, add)
{
if(typeof value !== 'String')
{
return value;
}
const num = parseFloat(value);
const mathNum = parseFloat(add);
const newNum = num + mathNum;
const stringNum = newNum.toString();
return stringNum;
}
})
});
I’m setting up my routing variable and my parameter as such:
$query->get('week')->add('1')
What am I doing wrong?
Also, if you’re willing to share, it would be helpful to know where I can use JS and jquery within the builder (for example, unless I’m mistaken, it seems like the attributes allow for this, but I’m not sure about the routing variables, query parameters, etc).
Thank you in advance!