How to set at least two characters in jQuery UI autocomplete?

前端 未结 3 1455
醉话见心
醉话见心 2021-02-20 15:49

I am using jQuery autocomplete and would like to limit the showing results only when the user types at least 2 characters. How to do that?

相关标签:
3条回答
  • 2021-02-20 16:35

    There is no minLength attribute. The attribute you are searching for is minChars.

    see https://github.com/devbridge/jQuery-Autocomplete

    0 讨论(0)
  • 2021-02-20 16:48

    for the record:

    The minimum number of characters a user has to type before the Autocomplete activates. Zero is useful for local data with just a few items. Should be increased when there are a lot of items, where a single character would match a few thousand items.

    Code examples

    Initialize a autocomplete with the minLength option specified.

    $( ".selector" ).autocomplete({ minLength: 0 });
    

    Get or set the minLength option, after init.

    //getter
    var minLength = $( ".selector" ).autocomplete( "option", "minLength" );
    //setter
    $( ".selector" ).autocomplete( "option", "minLength", 0 );
    

    minLengthIntegerDefault:1

    docs

    0 讨论(0)
  • 2021-02-20 16:49
    $( "#myselectbox" ).autocomplete({ minLength: 2 });
    
    0 讨论(0)
提交回复
热议问题