Can you calculate with input parameters in custom control?

Is it possible to do simple math with input parameters used for a custum control button?
At this point I'm thinking that it isn't possible in a straight forward way:

  • calculations in the command attribute is not possible
  • I could use a script instead of a command where we have access to parameters.*parameter1*, however, jinja will always interpret it as a sting, it can't convert it to a number and there is no obvious way to do calculations with it
  • I could opt for a Javascript snippet but it isn't possible to pass input parameters to Javascript.

Is this correct? Are there alternative routes I could try?

You could use a javascript approach with your command and then grab the values of the inputs using jQuery in that anonymous function call. The trick would be figuring out the input selectors. Like this I think...

function(){OctoPrint.control.sendGcode("M117 " + (parseInt($('input1_selector').val()) + parseInt($('input2_selector').val())));}

Thanks for your input once again!
In the end I got it to run like this:

var Xslope = Math.round((Number(document.getElementsByClassName("input-small")[0].value)
            - Number(document.getElementsByClassName("input-small")[1].value))*100)/10000;
            
var Yslope = Math.round((Number(document.getElementsByClassName("input-small")[2].value)
            - Number(document.getElementsByClassName("input-small")[3].value))*100)/10000;
           
OctoPrint.control.sendGcode('M891 X' + Xslope + ' Y' + Yslope); alert('Leveling
            completed with X-slope set to ' + Xslope + ' and Y-slope set to ' + Yslope);

It's kinde ugly but it works. Problem is that in this way the input for the JavaScript is pulled straight from the objects and to find the objects (which don't have unique ID's or classes... ) I need to rely on their order of occurance on the page.

I'm still working on finding the input selectors so I can give your code a go. Much nicer!

I can't remember how those are named currently and don't have any custom controls currently to look at, but my assumption is there is something that would make them unique to get around the order issue.