Sha256: 4d26586c5c29403b1ac979aedb80422b04f3dfd99b726d970a0d0e4745ada0d0

Contents?: true

Size: 973 Bytes

Versions: 1

Compression:

Stored size: 973 Bytes

Contents

/*
* Unobtrusive autocomplete
*
* To use it, you just have to include the HTML attribute autocomplete
* with the autocomplete URL as the value
*
*   Example:
*       <input type="text" autocomplete="/url/to/autocomplete">
* 
* Optionally, you can use a jQuery selector to specify a field that can
* be updated with the element id whenever you find a matching value
*
*   Example:
*       <input type="text" autocomplete="/url/to/autocomplete" id_element="#id_field">
*/

$(document).ready(function(){
  $('input[data-autocomplete]').each(function(i){
    $(this).autocomplete({
      source: $(this).attr('data-autocomplete'),
      select: function(event, ui) {
        $(this).val(ui.item.value);
        if ($(this).attr('id_element')) {
          $($(this).attr('id_element')).val(ui.item.id);
        }

        if($(this).attr('label_element')) {
          $($(this).attr('label_element')).val(ui.item.value);
        }
        return false;
      }
    });
  });
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails3-jquery-autocomplete-moc-0.3.1 lib/generators/templates/autocomplete-rails.js