diff --git a/octoprint_psucontrol/static/js/psucontrol.js b/octoprint_psucontrol/static/js/psucontrol.js index 74ccc8c..e98bb85 100644 --- a/octoprint_psucontrol/static/js/psucontrol.js +++ b/octoprint_psucontrol/static/js/psucontrol.js @@ -29,14 +29,18 @@ $(function() { }; self.onSettingsBeforeSave = function () { - if (self.scripts_gcode_psucontrol_post_on() != self.settings.scripts.gcode["psucontrol_post_on"]()) { - self.settings.plugins.psucontrol.scripts_gcode_psucontrol_post_on = self.scripts_gcode_psucontrol_post_on; - self.settings.scripts.gcode["psucontrol_post_on"](self.scripts_gcode_psucontrol_post_on()); + if (self.scripts_gcode_psucontrol_post_on() !== undefined) { + if (self.scripts_gcode_psucontrol_post_on() != self.settings.scripts.gcode["psucontrol_post_on"]()) { + self.settings.plugins.psucontrol.scripts_gcode_psucontrol_post_on = self.scripts_gcode_psucontrol_post_on; + self.settings.scripts.gcode["psucontrol_post_on"](self.scripts_gcode_psucontrol_post_on()); + } } - if (self.scripts_gcode_psucontrol_pre_off() != self.settings.scripts.gcode["psucontrol_pre_off"]()) { - self.settings.plugins.psucontrol.scripts_gcode_psucontrol_pre_off = self.scripts_gcode_psucontrol_pre_off; - self.settings.scripts.gcode["psucontrol_pre_off"](self.scripts_gcode_psucontrol_pre_off()); + if (self.scripts_gcode_psucontrol_pre_off() !== undefined) { + if (self.scripts_gcode_psucontrol_pre_off() != self.settings.scripts.gcode["psucontrol_pre_off"]()) { + self.settings.plugins.psucontrol.scripts_gcode_psucontrol_pre_off = self.scripts_gcode_psucontrol_pre_off; + self.settings.scripts.gcode["psucontrol_pre_off"](self.scripts_gcode_psucontrol_pre_off()); + } } };