mistic100 / jQuery-QueryBuilder

jQuery plugin offering an interface to create complex queries
https://querybuilder.js.org
MIT License
1.68k stars 552 forks source link

Input using Selectize: calling 'getSQL' returns a single string even though multiple inputs were selected #930

Closed VanHiro closed 2 years ago

VanHiro commented 2 years ago

The Issue

I am allowing the user to use the IN/NOT IN operator with the filters that have a selectize input. The issue is that even though the user selects multiple items the query-builder's GetSQL method treats the value as a single string. The retrieved string sql will contain IN('A,B,C'). But, if I execute the query in the DB with that value I will obtain a very different result than if I would with the expected outcome IN('A','B','C').

The code

Link to the jsFiddle example: http://jsfiddle.net/vanhiro/Lt2h7zse/1/

I linked an example of the situation but it is a mere visual representation since the issue is actually in the query-builder.standalone file.

---> This is how the input is handled normally from the query-builder

Code at line 5931 of query-builder.standalone.js This code will return IN('A,B,C').

rule.value.forEach(function(v, i) {

---> This is the solution that allows me to receive an array of strings inside the IN(...) stored in the SQL variable is:

This code will return IN('A','B','C')

  var condition;
  // Conditional to handle multiple values filter vs single value
  // Condition contains the value of the rule
  if(rule.value[0] instanceof Array) {
      condition = rule.value[0];
  } else {
      condition = rule.value;
  }
  condition.forEach(function(v, i) {

My point

Has anyone encountered this issue already and if so, how did they fix it without changing the query-builder file?

mistic100 commented 2 years ago

You must tell the builder that you are working with a multi value input.

Two solutions :

VanHiro commented 2 years ago

That does get me closer to where I want to go indeed, thank you. I will implement my code with those options and see which one better fits my needs.

VanHiro commented 2 years ago

I was approaching the issue from a different perspective and was hoping I could interdict the user from even trying to select multiple inputs for the equal operator but I see that the issue has been handled differently and it works.