Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery QueryBuilder not working

I am using JQuery QueryBuilder in my HTML page. I have followed the installation guide. My HTML head includes the following

    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
    <script src="bower_components/moment/moment.js"></script>
    <script src="bower_components/jquery-extendext/jQuery.extendext.js"></script>
    <link href="bower_components/bootstrap/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="bower_components/jQuery-QueryBuilder/dist/css/query-builder.default.css" rel="stylesheet" type="text/css" />
    <script src="bower_components/jQuery-QueryBuilder/dist/js/query-builder.standalone.js"></script>

My body has

<div id="builder"></div>

But when I use

<script>
  $('#builder').queryBuilder({
    filters: [ ... ]
  });
</script>

My Chrome console says

query-builder.standalone.js:437 Uncaught TypeError: Cannot set property 'queryBuilder' of undefined

All my bower componenets are installed properly.

What am I doing wrong?

like image 440
Jaseem Abbas Avatar asked Jun 28 '15 12:06

Jaseem Abbas


1 Answers

Move the script below the builder div element

<div id="builder"></div>

<script>
  $('#builder').queryBuilder({
    filters: [{id:1}] // You need to implement this
  });
</script>

or use Jquery document.ready

  $(document).ready(function(){
    $('#builder').queryBuilder({
        filters: [{id:1}] // You need to implement this
    });
  })
like image 137
Skarlinski Avatar answered Nov 18 '22 08:11

Skarlinski