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

Trigger submit on result click #67

Open
jaredatch opened this issue Dec 9, 2016 · 2 comments
Open

Trigger submit on result click #67

jaredatch opened this issue Dec 9, 2016 · 2 comments

Comments

@jaredatch
Copy link

jaredatch commented Dec 9, 2016

This isn't provided as an example and didn't appear in any past issues, so I wanted to note this for anyone who may search for this in the future.

If you want to trigger the form to submit on click, use the following:

onSelect: function(e,term,item) {
	$(document).find('input.search-autocomplete').each(function(index, el) {
		if ($(this).val() === term) {
			$(this).closest('form').submit();
		}
	});
}

Adjust .search-autocomplete to whatever the class is you are using on your text field. This also accomodate multiple search fields/forms on a page.

Probably would be a solid example to include in the documentation :)

@r3shad
Copy link

r3shad commented Sep 9, 2017

how can i rearrange it with following @jaredatch

onSelect: function(e, term, item){
console.log('Item "'+item.data('langname')+' ('+item.data('lang')+')" selected by '+(e.type == 'keydown' ? 'pressing enter or tab' : 'mouse click')+'.');

                $('#search').val(item.data('langname'));
            }

@TheSeer507
Copy link

I solved using this method:
onSelect: function(e,term){
document.getElementById("form_id").submit();
}
This will grab the suggested term from your autocomplete and trigger the form submit to start the search with a click

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

3 participants