Initializing jQuery selectize entry on page load

31 Views Asked by At

I am using selectize for a report to allow specific search terms to be added filter criteria. I save off the input entries to local storage (via Lockr) so that when users return to the page their criteria is still populated.

However, I am not sure how to load the selection from onInitialize.

<script type="text/javascript">
    !function (l) {
        "use strict";
        function e() { }
        e.prototype.initSelectize = function () {
            l("#selectize-skus").selectize({
                plugins: ["remove_button"],
                persist: !1,
                createOnBlur: !0,
                create: !0,
                onChange: function (value) {
                    Lockr.set('skus', value);
                },
                onInitialize: function () {
                    var skus = Lockr.get('skus');
                    if (skus)
                    {
                        this.setValue(skus);
                    }
                }
            });
        },  e.prototype.init = function () {
         this.initSelectize() },
        l.BillListSelectize = new e, l.BillListSelectize.Constructor = e
    }(window.jQuery), function () {
         "use strict";
         window.jQuery.BillListSelectize.init();
     }();
    </script>

You can see that when onChange fires, I save the selections to storage. Then onInitialize should pull those values back from storage and assign, if they exist. However, this doesn't seem to be working and I'm not sure why. I've seen others reference setValue but typically out of the context of the initializer.

0

There are 0 best solutions below