if ($('#listaBases').data('tipo') == 1) {
  var bases = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: {
                  url: 'json-bases-dato.php',
                      prepare: function (settings) {
                      settings.type = "POST";
                      settings.contentType = "application/json; charset=UTF-8";
                      return settings;
                  },
                  remote: function (query, settings) {
                      settings.type = "POST";
                      settings.data = {q: query, foo: 'bar'}; // you can pass some data if you need to
                      return settings;
                  }
              }
  });
  bases.initialize();
  var elt = $('#listaBases');
  elt.tagsinput({
    itemValue: 'value',
    itemText: 'text',
    maxTags: 1,
    typeaheadjs: {
      name: 'bases',
      displayKey: 'text',
      source: bases.ttAdapter(),
      limit: 50
    }
  });
  $('#listaBases').on('itemAdded', function(event) {
    $('#btnVerResultado').hide();
  });
  $('#listaBases').on('itemRemoved', function(event) {
    $('#btnVerResultado').hide();
  });
  
  $('#btnLimpiarBases').on('click', function () {
    $.confirm({
      title: 'Confirmar',
      content: '¿Elimina todos las bases de dato cargadas?',
      buttons: {
        Si: function () {
          $('#listaBases').tagsinput('removeAll');
          $('#btnVerResultado').hide();
        },
        no: function () {
          //$.alert('Cancelado!');
        },
      }
    });
  });
}
else {
  $('#listaBases').select2();
  /*$("#listaBases").on("select2:selecting", function(e) {
    console.log($(this).val(), e.params.args.data);
    if($(this).val() && $(this).val().length >= 1) {
      e.preventDefault();
    }
  });*/
  $('#listaBases').on("change", function (e) { $('#btnVerResultado').hide(); });

  $('#btnLimpiarBases').on('click', function () {
    $.confirm({
      title: 'Confirmar',
      content: '¿Elimina todos las bases de dato cargadas?',
      buttons: {
        Si: function () {
          $('#listaBases').val(null).trigger('change');
          $('#btnVerResultado').hide();
        },
        no: function () {
          //$.alert('Cancelado!');
        },
      }
    });
  });
}

