jQuery-QueryBuilder
jQuery-QueryBuilder copied to clipboard
Select with dynamic multiple (Defaut false, make it as true for in and not_in)
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.
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.
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);
}
}
}