0

I have a working Python/Django search form that I need to integrate with my JavaScript tagging script on the front end, so my user's search terms are turned into tags.

The problem is my search form works with ?query=Bee but not ?query=[]Bee. I need to remove the brackets so my search form will work again. Can someone help me adapt my JavaScript to prevent [] being passed into the URL?

HTML SEARCH FORM html page

<form name="input" role="search" class="form-search" action="fridge" method="get">
        <div class="row">
            <div class="col-md-6">    
                <div class="example-wrapper">
                    <div class="tags well">
                        <div placeholder="Enter search" data-tags-input-name="query" id="tag"></div>
                    </div>
                </div>
            </div>
             <br>
            <div class="form-group col-md-3">
                  <button type="submit"  id="searchsubmit" class="btn btn-xlarge rounded-pill btn-block shadow-sm">Search</button>
            </div>   
        </div>          
</form>

Javascript html page

    $( document ).ready(function() {
        var t = $( "#tag" ).tagging();
        t[0].addClass( "form-control" );
        // console.log( t[0] );

    });
})( window.jQuery, window, document );

var tagBody = '(?:[^"\'>]|"[^"]*"|\'[^\']*\')*';

var tagOrComment = new RegExp(
    '<(?:'
    // Comment body.
    + '!--(?:(?:-*[^->])*--+|-?)'
    // Special "raw text" elements whose content should be elided.
    + '|script\\b' + tagBody + '>[\\s\\S]*?</script\\s*'
    + '|style\\b' + tagBody + '>[\\s\\S]*?</style\\s*'
    // Regular name
    + '|/?[a-z]'
    + tagBody
    + ')>',
    'gi');
function removeTags(html) {
  var oldHtml;
  do {
    oldHtml = html;
    html = html.replace(tagOrComment, '');
  } while (html !== oldHtml);
  return html.replace(/</g, '&lt;');
}

Link to tagging CDN: https://cdn.rawgit.com/sniperwolf/taggingJS/master/tagging.min.js

E Wilson
  • 125
  • 2
  • 10
  • How is the code related to the problem? There's nothing that would produce this strange query string. – Andreas Oct 11 '19 at 16:19
  • Many thanks, Andreas for getting in touch in regard to this, it really is appreciated. I've updated my question and included the HTML form and a link to the rest of the tagging script. It's definitely something here that's causing the issue as when I remove the JS it works fine. If you can provide more assistance I will greatly appreciate it. – E Wilson Oct 11 '19 at 23:09
  • The query string is not like you've posted. The name of the input fields is `query[]` because there can be more than one tag. This will produce `?query[]=...` which is one way to submit a key which can have multiple values. [How to pass an array within a query string?](https://stackoverflow.com/questions/6243051/how-to-pass-an-array-within-a-query-string) – Andreas Oct 12 '19 at 06:01

0 Answers0