jQuery-QueryBuilder icon indicating copy to clipboard operation
jQuery-QueryBuilder copied to clipboard

Select with dynamic multiple (Defaut false, make it as true for in and not_in)

Open sekarpdkt opened this issue 4 years ago • 2 comments

Is there a way make select (standard and select2 plugin) by default multiple as false, but when operator is selected as in or no_in, make it as multiple. In the basic / all examples, I am able to select operator as in or not_in, but will allow only one select.

sekarpdkt avatar Jun 03 '20 02:06 sekarpdkt

No way I can think of. The only thing you can do for now is the always make the filter multiple. If the user wants an "equal" he will have to choose "in" with a single value.

mistic100 avatar Jun 03 '20 09:06 mistic100

This workaround seems like working.


        $(`#qb`).on('afterUpdateRuleOperator.queryBuilder', function (e, rule) {
            if (rule.filter && rule.filter.input=="select") {
                try{
                    rule.$el.find('.rule-value-container select').select2('destroy');
                }catch(e){}
                var hybridOperators = ['in','not_in'];
                if (hybridOperators.indexOf(rule.operator.type) == -1) {
                    rule.filter.multiple=false;
                    rule.filter.plugin_config.multiple=false;
                    rule.$el.find('.rule-value-container select').select2(rule.filter.plugin_config);
                } else {

                    rule.filter.multiple=true;
                    rule.filter.plugin_config.multiple=true;
                    rule.$el.find('.rule-value-container select').select2(rule.filter.plugin_config);

                }
            }
      }

sekarpdkt avatar Jun 03 '20 16:06 sekarpdkt