Advertisement
jynk

Untitled

Jul 20th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.98 KB | None | 0 0
  1. $( "#userSchool" )
  2.             // don't navigate away from the field on tab when selecting an item
  3.             .bind( "keydown", function( event ) {
  4.                 if ( event.keyCode === $.ui.keyCode.TAB &&
  5.                         $( this ).data( "autocomplete" ).menu.active ) {
  6.                     event.preventDefault();
  7.                 }
  8.             })
  9.             .autocomplete({
  10.                 source: function( request, response ) {
  11.                    
  12.                     $.getJSON( "<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php",
  13.                     {
  14.                         term: extractLast( request.term ), action: 'filter_schools', postType: 'school'
  15.                     },
  16.                     response );
  17.  
  18.                 },
  19.  
  20.                 select: function( event, ui ) {
  21.                    
  22.                     var terms = split( this.value );
  23.                     // remove the current input
  24.                     terms.pop();
  25.                     // add the selected item
  26.                     terms.push( ui.item.value );
  27.                     // add placeholder to get the comma-and-space at the end
  28.                     terms.push( "" );
  29.                     this.value = terms.join( ", " );
  30.                     return false;
  31.                    
  32.                 },
  33.                 open: function() { $('.ui-menu').width(300) }
  34.                
  35.             });
  36.  
  37.       });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement