I want to develop a plugin that place some input fields in the sidebar and if the user press "print" the plugin should validate the input values.
If the values are not valid, I want to do some kind of "veto" -> print should not start.
Is this possible, do you have an idea how to solve this? Any idea is welcome!
BR
Olli
You can override the print()
function in the printerstate
view model. Take a look at the FilamentManager plugin if you need some sample code. The downside of this is that it can be a compatibility issue between plugins and it only works if the print was started from the web interface
Thx for your feedback.
I was hoping to find some event or exception-mechanism, because I am not a javascript-fan.
But your solution looks really nice!
hmm... if many plugins use your methode, it should work!?! Each print-methode is "on a stack", I think....
Second point: In my situation the user inputs some values via web-interface, so it is valid!
I think I will start a PoC with your js.
Olli
I have some code in Octolapse that cancels a print after it's already started depending on some error conditions (camera not working, octoprint is wrong version, printer profile not selected, etc), but there are problems with Start Gcode stored in Octoprint at the moment (I put in a feature request to deal with this). Other than that it works.
Let me know if this seems to fit your needs and I can dig up some code.
@FormerLurker Do you thing about to switch to the javascript solution from @NB4cSUYn ?
Because this is all done in the frontend, so the printer q-code queue is not involved -> no canceling needed!
I only mentioned my solution because you're not a javascript fan , and because it allows for different methods of starting a print and can potentially reduce compatibility issues.
That being said it's much simpler to do this client side as @NB4cSUYn suggests. You could also attach an event to the print button itself, but that's probably not the best way.