Sha256: ca9cfddcdc1641e62eb4589a001070a8ba32fb136d685d6fd02a358412e4e51b

Contents?: true

Size: 944 Bytes

Versions: 5

Compression:

Stored size: 944 Bytes

Contents

$(function() {
  $('.rails-autocomplete').typeahead({
    source: function(query, process) {
      items = [];
      map = {};
      return $.ajax({
        url: $(this)[0].$element.data('autocomplete-url'),
        context: $(this)[0].$element,
        type: 'get',
        data: { q: query },
        dataType: 'json',
        beforeSend: function(xhr) {
          $(this).toggleClass('rails-autocomplete-loading');
        },
        success: function(data) {
          $.each(data, function (i, item) {
            map[item.name] = item;
            items.push(item.name);
          });
          $(this).toggleClass('rails-autocomplete-loading');
          return process(items);
        }
      });
    },
    updater: function(item) {
        selectedItem = map[item].id;
        $('input[data-autocomplete-child=' + $(this)[0].$element.data('autocomplete-parent') + ']').attr('value', selectedItem);
        return item;
    }
  });
});

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_autocomplete-0.0.6 vendor/assets/javascripts/rails_autocomplete/autocomplete.js
rails_autocomplete-0.0.5 vendor/assets/javascripts/rails_autocomplete/autocomplete.js
rails_autocomplete-0.0.4 vendor/assets/javascripts/rails_autocomplete/autocomplete.js
rails_autocomplete-0.0.3 vendor/assets/javascripts/rails_autocomplete/autocomplete.js
rails_autocomplete-0.0.2 vendor/assets/javascripts/rails_autocomplete/autocomplete.js