Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is possible to show autosuggestions list after user click in show input? #376

Open
jakubstankowski opened this issue Jul 30, 2019 · 1 comment

Comments

@jakubstankowski
Copy link

Hi!

I have question - it is possible to show suggestions list after user click in input ?
I mean something like google, show list only click in input

thanks for answer!

@salt-istanbul
Copy link

salt-istanbul commented Aug 30, 2019

Hi,
I found a pretty simple solution. You may show predefined suggestions on focus when query is blank.

$('.typeahead').typeahead({
		    source: function (query, process) {
		    	if(query == ""){
                                //query is blank: show predefined suggestions
                                return this.process([{"id":172,"name":"default item 01","url":"http://www.test.com"},{"id":73,"name":"default item 02","url":"http://www.test2.com"}]);
		    	}else{
                                 //query is not blank: make an ajax call
			    	 return $.post("http://example.com/query", { query: query } , function (data) {
			              data = $.parseJSON(data);
			              return process(data);
			        });		    		
		    	}
		    },
		    fitToElement : true,
		    minLength : 2,
		    theme : "bootstrap4",
		    afterSelect: function(args){
		         window.location.href = args.url;
		    },
		}).on("focus", function(e){
			if($(this).val() == ""){
				var typeahead = $(this).data("typeahead");
				    typeahead.query="";
				    typeahead.source("");
		    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants