vuejs-autocomplete icon indicating copy to clipboard operation
vuejs-autocomplete copied to clipboard

search min characters

Open hakankoralturk opened this issue 6 years ago • 6 comments

How do I get the search to start when I type a minimum of 3 characters? Or more. I didn't find anything like min-length.

hakankoralturk avatar Dec 13 '18 14:12 hakankoralturk

Any update here?

kiran94 avatar Jan 28 '19 17:01 kiran94

+1 this is an important one... 👍

diogolessa avatar Apr 17 '19 01:04 diogolessa

+1

tfpdeveloper avatar Oct 18 '19 15:10 tfpdeveloper

Hi everyone,

Just wanted to offer a somewhat hacky solution for this. You can set @results="showResults" on the autocomplete component and then add a method called showResults with this inside it, just change the .length condition to check for the min chars you want. I used jquery but it could easily be done with vanilla js as well.

  showResults(){
            
                this.$nextTick(()=>{
                    if($('.autocomplete__inputs input[type=text]').val().length===0){
                        $('.autocomplete__results').hide()
                    }
                    else
                        $('.autocomplete__results').show()
                })
            
           
        }

mattlee1 avatar Feb 26 '20 17:02 mattlee1

+1

vitaliss avatar Jun 19 '20 22:06 vitaliss

Hi,

Very nice library. Would be even nicer if the minimum input would be configurable.

Another hacky solution is making the endpoint dynamic. The loading icon is still visible. And you could extend this by making 3 dynamic and show a message when the input length is below this number. My purpose is limiting the api calls by the way so this works for me (for now):

        `:source="endpoint"`

then add the method

        ```endpoint: function(input) {

            if (input.length < 3) {

                return false;

            }

            return 'https://{{Your_Endpoint}}?key={{Your_Api_Key}}&q=' + input
        },```

Finally hide the error message (in my case I put it in the styles block of my single file component:

    .autocomplete__results__item--error {
        display: none;
    }

de-raaf-media avatar Jul 03 '20 10:07 de-raaf-media