Skip to content

Issue with selectize itegration - Option labels always "undefined" #271

@C4rter

Description

@C4rter

Hi, I'm integrating the query builder into a site I'm working on. It's really great and for the most part easy to work with.

But I've got an issue with the selectize integration. I used the example as a base but even with the example code, all the options are showing up as "undefined".
undefined

That's my filter config:

{
id: 'query_theme',
label: 'Theme',
type: 'string',
operators: ['equal'],
plugin: 'selectize',
plugin_config: {
valueField: 'id',
labelField: 'query_theme',
searchField: 'query_theme',
sortField: 'query_theme',
create: true,
maxItems: 1,
plugins: ['remove_button'],

            onInitialize: function() {
                var that = this;
                if (localStorage.demoData === undefined) {
                    $.getJSON('http://querybuilder.js.org/assets/demo-data.json', function(data) {
                        localStorage.demoData = JSON.stringify(data);
                        data.forEach(function(item) {
                            that.addOption(item);
                        });
                    });
                }
                else {
                    JSON.parse(localStorage.demoData).forEach(function(item) {
                        that.addOption(item);
                    });
                }
            }
        },
        valueSetter: function(rule, value) {
            rule.$el.find('.rule-value-container input')[0].selectize.setValue(value);
        }
    }

I've also included this code from the example:

// Fix for Selectize
$('#builder').on('afterCreateRuleInput.queryBuilder', function(e, rule) {
if (rule.filter.plugin == 'selectize') {
rule.$el.find('.rule-value-container').css('min-width', '200px')
.find('.selectize-control').removeClass('form-control');
}
});

Strangly, the option ids are all there in the source code of the page, but all the labels are somehow undefined. I hope you can help me with this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions