Submit with ENTER key and catcomplete widget

Submit with ENTER key and catcomplete widget

I have the following code and I'd like to submit the form when hit ENTER key:


  1. $(document).ready(function(){
  2.   
  3.   $('input[data-autocomplete]').live('focus', function(i){
  4.     $(this).catcomplete({    
  5.       delay: 500,      
  6.       source: $(this).attr('data-autocomplete'),
  7.       select: function(event, ui) {
  8.         $(this).val(ui.item.value);
  9.         if ($(this).attr('id_element')) {
  10.           $($(this).attr('id_element')).val(ui.item.id);
  11.           $($(this).attr('id_hidden_element')).val(ui.item.id);
  12.         }
  13.         return false;
  14.       }
  15.     });
  16.   });
  17.   
  18.   $.widget("custom.catcomplete", $.ui.autocomplete, {
  19.     _renderMenu: function( ul, items ) {
  20.       var self = this,
  21.       currentCategory = "";
  22.       $.each( items, function( index, item ) {
  23.         if ( item.category != currentCategory ) {
  24.           ul.append( "<li class='category'>" + item.category + "</li>" );
  25.           currentCategory = item.category;
  26.         }
  27.         self._renderItem( ul, item );
  28.       });
  29.     }
  30.   });
  31. });

I tried this simple solution, but I don't know how to implement it properly in my case:  http://forum.jquery.com/topic/autocomplete-and-enter-key

Thank You for help.





    • Topic Participants

    • emmek