A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/selectize/selectize.js/issues/522 below:

Load Items into Remote Control

So I see a lot of threads related to this issue.

#366 | #77 | #364

Here is what I did for a fix until it gets patched:

With PHP, I am adding a json object of the items I want to pass in via the values data param:

 <input name="redirect_parameter_model" class="bigdrop col-md-12 no-padding selectized" data-values="[{"id":"203","value":"Joypad C102"},{"id":"203","value":"Joypad C74"}]" value="" tabindex="-1" placeholder="Select a Model">

Within the selectize object I use the onintialise method

onInitialize: function() {
    var objects = [];

    $.each(elem.data('values'), function (i, b) {
        objects[b.value] = { id: b.id, model: b.value };
    });

    v.selectize.preLoad(objects);
}

Note, model is my valueField, labelField and searchField.

As I am looping and creating the object, I then pass over to a custom method that I created called preLoad. Which I placed under "refreshOptions".

preLoad: function(data) {
    var self = this;

    //  Add options to be able to insert the items
    this.options = data;            

    // Add items
    Object.keys(data).forEach(function(key) {
        self.addOption(key);
        self.addItem(key);
    });

    // Clear Options
    self.options = self.sifter.items = {};
},

Now I get items added in with no problems on init of the control 👍

Hopefully this gets added / or used for better functionality in the base :)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4