Custom_bindings event routing question

I am in the middle of a Plugin project that in the first half of the build out of settings, I only needed to save simple values. For this I made use of the "on_settings_save" event. In the second half of the screen I have the need for some callbacks and other script. I created some scripts and set the settings bindings to custom_bindings=True . This had the affect as expected for brining in the js file and related functionality. However, The event for "on_settings_save" seems to have stopped firing. I am not a pro with Python or the jinja2 templating system so I took a look at another Plugin(GPIO Control) that seems to make use of both custom_bindings=True and the on_settings_save event and they seems to work together as I would have expected.

In short if I set custom_bindings=True, the event for on_settings_save does not fire. If I set it to False, it does. Very repeatable.

Any pointer in the right direction on what I might be missing would be appreciated.

The on_settings_save function in your plugin will only fire if some settings are changed. When you use custom_bindings=True, your plugin needs to bind to the settings view model, which probably means you need to update your bindings.

In my plugins, I have a dependency in the JS viewmodel on settingsViewModel, and then set self.settingsVM = parameters[0], followed by all references in the Jinja templates such as data-bind="value: settingsVM.settings.plugins......

When you switch custom bindings around, you will have to change a couple more things in the frontend I suspect to get the settings to actually work.

Thanks for your comments. This has made me realize that the change to including the custom bindings has altered how the bindings for my existing template settings are seen which means that when I make a change to them, it is not actually "making the change" which is likely why I am not getting the on_settings_save event. I will investigate and confirm.

1 Like

Basically you changed the context of your binding and thus have to adjust those bindings to the new context.

After a bit more review of other plugins, ( @jneilliii some excellent work out there! ) as well as time spent reading on Knockout along with the very sparse documents in Viewmodels β€” OctoPrint master documentation, I was able to get things working in a way that I am happy with. Now back to the core feature work. Thank you both for your comments. They were helpful in getting me to think in the right direction.

1 Like