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

Extra network traffic on deleting term #65

Closed
dhauslad opened this issue Feb 28, 2013 · 2 comments
Closed

Extra network traffic on deleting term #65

dhauslad opened this issue Feb 28, 2013 · 2 comments
Assignees
Milestone

Comments

@dhauslad
Copy link

In the best picture winners example, typeahead is configured like this:

$('.example-films .typeahead').typeahead([
  {
    name: 'best-picture-winners',
    remote: '../data/films/queries/%QUERY.json',
    prefetch: '../data/films/post_1960.json',
    template: '<p><strong>{{value}}</strong> – {{year}}</p>',
    engine: Hogan
  }
]);

If I enter "b", it issues a network request to

http://twitter.github.com/typeahead.js/data/films/queries/b.json

for which the response is

[
  {
    "year": "1928/1929",
    "value": "The Broadway Melody",
    "tokens": [
      "The",
      "Broadway",
      "Melody"
    ]
  },
  {
    "year": "1935",
    "value": "Mutiny on the Bounty",
    "tokens": [
      "Mutiny",
      "on",
      "the",
      "Bounty"
    ]
  },
  {
    "year": "1946",
    "value": "The Best Years of Our Lives",
    "tokens": [
      "The",
      "Best",
      "Years",
      "of",
      "Our",
      "Lives"
    ]
  },
  {
    "year": "1957",
    "value": "The Bridge on the River Kwai",
    "tokens": [
      "The",
      "Bridge",
      "on",
      "the",
      "River",
      "Kwai"
    ]
  },
  {
    "year": "1959",
    "value": "Ben-Hur",
    "tokens": [
      "Ben-Hur"
    ]
  }
]

Good.

Now if I delete the 'b' from the input, typeahead issues a request to:

http://twitter.github.com/typeahead.js/data/films/queries/.json

Which comes back with a 404. If there isn't a way to prevent this request, this is a bug.

@whatcould
Copy link

Preventing suggestions where the query.length === 0 is a good step. But it might be better to just have an option for a minimum query length before suggestions are shown? It could be set to zero by default. In some cases, you might not want to search on just one or two characters either.

@jharding
Copy link
Contributor

Having an option for a minimum query length before making remote calls is a good idea, I'll have to keep that in mind.

For v0.8.2, I'm going to prevent suggestions from being retrieved if the query is empty or just whitespace.

@ghost ghost assigned jharding Feb 28, 2013
jlbooker added a commit to jlbooker/typeahead.js that referenced this issue Nov 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants