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

Missing last character when trying to get query value in "empty" template #114

Open
andregoldstein opened this issue Sep 24, 2015 · 0 comments

Comments

@andregoldstein
Copy link

I'm struggling with this one a little. I've been trying to output a message such as:

"Breaking Bad" couldn't be found in your collection.

in the designated "empty" template that I'm setting in data-templates

To do this I'm targeting the value of the input using jQuery and passing it off to a Session variable that I then call as a helper in my empty template. The call works except the query is always missing the final character. Strangely if I inspect the Session variable in my console, the full query is there.

Is there any reason why this shouldn't work with Typeahead?

Form template

<template name="bookSearchForm">

  <form action="/books/search" class="search searchBooks" method="post">
    <button class="searchBooksButton"><i class="fa fa-search"></i></button>
    <input id="searchBooksQuery" class="form-control typeahead" type="text"
       placeholder="Search for books in your collection or to add a new one"
       autocomplete="off" spellcheck="off"
       data-source="books" data-select="selected" data-templates="searchItem;empty:searchNoItems" />
  </form>

</template>

Empty template

<template name="searchNoItems">
  <div class="search-no-results">
    <span class="lookupBook">{{ bookSearchValue }} not in your collection, hit enter to search for it.</span>
  </div> <!-- /.search-no-results -->
</template>

JS

Template.bookSearchForm.events

  'keyup #searchBooksQuery': (e) ->
    bookVal = e.target.value 
    Session.set 'bookSearchValue', bookVal
Template.searchNoItems.helpers
  bookSearchValue: ->
    return Session.get 'bookSearchValue'
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

1 participant