Getting a custom event to fire #163

Closed
shaneprice opened this Issue Apr 1, 2013 · 4 comments

Comments

4 participants
@shaneprice

First off I have been playing with the typeahead for the last hour and it looks awesome! good work!

How am I meant to trigger an event I found https://github.com/twitter/typeahead.js/blob/master/README.md#custom-events

Trying

 autocompleted: autocompleteResult(),
        selected: selectedResult()
}
);

function openedResult() {
    console.log("openeed");
}
function autocompleteResult() {
    console.log("auto");
}
function selectedResult() {
    console.log("Selected");
}

Doesnt work. Any suggestions?

@jharding

This comment has been minimized.

Show comment
Hide comment
@jharding

jharding Apr 1, 2013

Contributor

So assuming this was your markup:

<input class="typeahead" type="text">

This is how you would listen for those custom events:

$('.typeahead')
.typeahead(/* pass in your datasets and initialize the typeahead */)
.on('typeahead:opened', onOpened)
.on('typeahead:selected', onAutocompleted)
.on('typeahead:autocompleted', onSelected);

function onOpened($e) {
  console.log('opened');
}

function onAutocompleted($e, datum) {
  console.log('autocompleted');
  console.log(datum);
}

function onSelected($e, datum) {
  console.log('selected');
  console.log(datum);
}

The custom events are just jQuery events that are triggered in the input element.

Contributor

jharding commented Apr 1, 2013

So assuming this was your markup:

<input class="typeahead" type="text">

This is how you would listen for those custom events:

$('.typeahead')
.typeahead(/* pass in your datasets and initialize the typeahead */)
.on('typeahead:opened', onOpened)
.on('typeahead:selected', onAutocompleted)
.on('typeahead:autocompleted', onSelected);

function onOpened($e) {
  console.log('opened');
}

function onAutocompleted($e, datum) {
  console.log('autocompleted');
  console.log(datum);
}

function onSelected($e, datum) {
  console.log('selected');
  console.log(datum);
}

The custom events are just jQuery events that are triggered in the input element.

@shaneprice

This comment has been minimized.

Show comment
Hide comment
@shaneprice

shaneprice Apr 1, 2013

Ahh easier then I thought. Thanks Jake for such a quick response.

Ahh easier then I thought. Thanks Jake for such a quick response.

@uuf6429

This comment has been minimized.

Show comment
Hide comment
@uuf6429

uuf6429 Oct 18, 2014

@jharding is there a reason why you did:

.on('typeahead:selected', onAutocompleted)
.on('typeahead:autocompleted', onSelected);

instead of:

.on('typeahead:autocompleted', onAutocompleted)
.on('typeahead:selected', onSelected);

uuf6429 commented Oct 18, 2014

@jharding is there a reason why you did:

.on('typeahead:selected', onAutocompleted)
.on('typeahead:autocompleted', onSelected);

instead of:

.on('typeahead:autocompleted', onAutocompleted)
.on('typeahead:selected', onSelected);
@momelnyk

This comment has been minimized.

Show comment
Hide comment
@momelnyk

momelnyk Nov 25, 2014

thank you, it was useful

thank you, it was useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment