πŸ‡ΊπŸ‡¦ We stand with Ukraine! πŸ‡ΊπŸ‡¦

Help with plugin not saving settings

Looking for help with a plugin not saving the settings. I have forked the code for JamSentry as I was unable to get in touch with the original developer. I've managed to update it to Python3 (don't know a lick of Python) and I have everything working, except it will not save the settings. So long as I keep the browser window open, the settings remain, but as soon as I close it they get wiped out. I have a feeling it's something in the JavaScript file, but I'm new to all of this. Can someone please take a look and possibly point me in the right direction? Thank you.

It's because the way the knockout js bindings are done. There are two ways to resolve it. You can either change your bindings to use the full path the settingsViewModel or update the setData callback to include the additional settings that you've added like it's doing for ip address here.

and example of the first option would be changing this line to this:

<input type="text" class="input-block-level" data-bind="value: settingsViewModel.settings.plugins.jamsentry.ipaddr">

that way the fields are directly binding to the settingsViewModel and you can remove the setData callback entirely.

Just thought of a third option. You can keep the binding as is and change how the template is loaded in init.py using this.

    def get_template_configs(self):
        return [dict(type="settings", custom_bindings=False, template="jamsentry_settings.jinja2")]

and technically don't need anything inside your js file and it becomes this.

$(function() {
    class JamSentryViewModel {
        constructor(parameters) {
            var self = this;

            self.settingsViewModel = parameters[0];
        }
    }

    // This is how our plugin registers itself with the application, by adding some configuration
    // information to the global variable OCTOPRINT_VIEWMODELS

        // ADDITIONAL_VIEWMODELS.push([
        OCTOPRINT_VIEWMODELS.push([
            // This is the constructor to call for instantiating the plugin
            JamSentryViewModel,

            // This is a list of dependencies to inject into the plugin, the order which you request
            // here is the order in which the dependencies will be injected into your view model upon
            // instantiation via the parameters argument
            ["settingsViewModel"],

            // Finally, this is the list of selectors for all elements we want this view model to be bound to.
            [("#tab_plugin_jamsentry")]
        ]);
});

but would have to update your tab jinja file to be

<iframe class="frame" data-bind="attr: {src: settingsViewModel.settings.plugins.jamsentry.ipaddr()}" alt="Enter the address of the JamSentry in settings to see its status field"></iframe>

Thanks for the response. Unfortunately, none of these options have worked. Still unable to save the settings.

Ah, I think I see why it's not working. Capitilization on your plugin_identifier is important...here's the third option implemented and functioning...changed the plugin id along with the other previously mentioned changes.

Thank you so much! Working as expected now using your code changes. Will update mine to reflect as I will be adding the hardware changes I made to the wiki along with updated STLs. Thanks again!