Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Load Items into Remote Control - Hack (working for me) #522

Closed

Description

@paulm17

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 :)

Activity

  1. YevSent commented on Aug 7, 2014

    @YevSent

    @no1youknowz, thanks for your decision, it very helpful for me. Good job 👍

  2. YevSent commented on Aug 8, 2014

    @YevSent

    Also, in my case, I've added selectize.clearOptions(); before set options to correct items creating.

  3. brianreavis commented on Jan 30, 2015

    @brianreavis
    Member

    See the 0.12.0 release for this. Selectize now recognizes the dataAttr attribute (data-data by default) for populating the initial values.

  4. vedsingh-fullstack commented on Aug 20, 2015

    @vedsingh-fullstack

    Can u give an example of how u used preLoad .Can it be used with ajax so that the options are populated based on ajax data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions