2011-07-23 37 views
1

有沒有一些方法可以告訴jQuery UI自動完成從不搜索?我想可以設置minLength真的很高,但是有一個合適的方法可以做到嗎?jQuery UI自動完成:永遠不會彈出?

如果您想知道,我會用onclick事件手動觸發它。


我如何添加onclick處理程序:

if(settings.showOnClick) { 
    $(this).bind('click.ajaxselect', function(e) { 
     if(!$(this).data('focusHandled') && !$(this).autocomplete('widget').is(':visible')) { 
      $(this).autocomplete('search',''); 
      $(this).data('focusHandled',true); 
     } else { 
      $(this).data('focusHandled',false); 
     } 
    }).bind('focus.ajaxselect', function(e) { 
     if(!$(this).data('focusHandled') && e.hasOwnProperty('originalEvent') && $(this).val() === this.defaultValue && !$(this).autocomplete('widget').is(':visible')) { 
      $(this).autocomplete('search',''); 
      $(this).data('focusHandled',true); 
     } else { 
      $(this).data('focusHandled',false); 
     } 
    }) 
} 

回答

1

設置minLength到任何你想要的(可能是0,因爲你手動觸發)。然後,

$(".selector").autocomplete({ 
    select: function(event, ui) { 
     ... // do your thing 
     $(".selector").autocomplete("disable"); 
    } 
}); 

$(".clicker").click(function() { 
    ... // do your thing 
    $(".selector").autocomplete("enable"); 
}); 
+0

禁用它似乎取消搜索,即使點擊。 – mpen

+0

您是如何在點擊時激活自動填充功能的? –

+0

請參閱更新。 – mpen

1

search回調把這個似乎做主要是我想:

search: function(e, ui) { 
    if(settings.minLength < 0 && e.hasOwnProperty('originalEvent')) return false; 
    // other code 
    return true; 
}, 

然後如果我設置minLength小於0,輸入事件將不會觸發搜索,但我的手動點擊事件仍然會。不過,焦點活動似乎也被取消了。試圖確定我是否對這種行爲感到高興。