Sha256: 5ff7a5255bd828a72f5985b33e82044fcee82349982b405402d260894d4da7d0

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

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" data-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]').live('focus', function(i){
    $(this).autocomplete({
      minLength: 3,
      delay: 50,
      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);
        }

        if(this.form.elements['auto_submit'].value == "true")
        {
            this.form.submit();
        }
        else
        {
            return false;
        }
        return false;
      }
    });
  });
});

Version data entries

1 entries across 1 versions & 1 rubygems

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