-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
how to re-initialize typeahead #41
Comments
There's not really a good way of doing this right now. Perhaps this is something we can look to add in v0.9. |
CORRECTION: The code below does not work neither :( data is not being prefetched again. I guess the only solution so far is to do an AJAX refresh with jQuery + .html() so the JS is executed... We are currently doing this hacky approach to "reset" a typeahead: Given this markup: And this JS: We init it: And we call this function to reset it without a full page reload (after for example adding a new tag): If you guys at Twitter are going to implement a nice reset solution in a near future would be great, I would prefer not to dig and modify lots of the code just to see a good approach built by you later and throw it away :) Anyway, thanks for the component, despite the limitations it is great! |
Yes, it'd be excellent if there was a reset. I leapt in and got a demo working v quickly (probably too quickly, I should have thought things through a bit more...!) and then realised the pre-fetched stuff wasn't ever being updated as it was working with the local storage copy. Some method to drop it would be great - I'm sure there are a wide variety of scenarios people will have depending on just how static their data is and how it gets updated, but my one is that the local storage/pre-fetch items will gradually go stale and I'd thus want to refresh periodically (and maybe on demand) with the compromise being between maintaining 100% accuracy and using local storage for speed / minimising server hits. |
I'll look into implementing this functionality later this week and if all goes well, I'd be willing to ship it in v0.8.2. Stay tuned. |
Thanks for this very useful feature, unfortunately I tried to use it and seems not working. I checked the code many times, the $("#dropbox_city").val() changes correctly value, Thanks |
Same problem than @alexdesi, the remote url never changes... any clue ? |
The $('.typeahead1').typeahead({
name: 'remote',
remote: '/search?q=%QUERY'
});
$('.typeahead2').typeahead({
name: 'remote',
remote: '/path/search?q=%QUERY'
}); Both typeaheads will make requests to Hope that helps. Oh and sorry @alexdesi for not responding, I'm not sure how I missed your comment. |
Ok thanks, I'll try that. |
It would be very nice to be able to clear out the dataset cache. There are a few reasons that I can think of
|
@jeffmax can you create a separate issue for adding something like that? |
Thanks, been looking for this :) |
https://github.com/tellex/typeahead.js/commit/7a10abf0fd958883b2b009622caa977b15d26994 Added refreshCache method. So if you have multiple datasets binded to a typehead and u need to change a particular dataset value simple call $(".input-box").typeahead("refreshCache",[{name:Dataset1, url: "New URL"}]); -> Is important to always add "[]" because refreshCache expects an array of objects. This function will find all dataset cached to the typeahead and walk trought the array to find the matching dataset.name then it will check which attributes values changed and replace the new ones , refresh the associated cache object, and reinitialize the typeahead. I added an new event called typeahead:dropdownOpened the reason behind this is that if add a new refreshCache dataset i will reinitialize the typeahead and destroy previously DOM created object ... so if u have binded an event to a element in the displayed suggestions Box it will be lost.... the solution to this: Hope you enjoy the new function , sorry for my bad grammar my native languaje is spanish.... Greetings from argentina!!! |
I forgot to mention to complete destroy cache objects call $('....').typeahead('destroy','NoCached') |
var url = javaRest.rPath + '/role/auto?searchKeyword';
var list = [];
$('#user-edit-companyName').typeahead([
{
name: "test",
prefetch: list,
remote: {
url: url + '=%QUERY',
filter: function (data) {
list.push(data);
return data;
}
}
}
]);
what about this one?
|
@jharding thanks for that comment... totally got me out of the jam I was in. |
@jharding same here. #41 (comment) saved me on an Ajax application. |
Fixed 404 links
hi is there a i am using * typeahead.js 0.10.5 is there a way i can change the typeahead source and template on runtime? |
@rushdy20 Did you ever find a way to do this? I have the exact same problem. Right now I initialize the typeahead in a focusOut event from an other input field, but it isn't working that well. |
im using typehead in item search in text box (get value from the localstorage) after add new data it's stored in to local storage this new data came in localstorage which i use localstorage value alert. but this typehead not coming that localstorasge new data.[Please kindly help me how to get local storage new added data get it in to the typehead prefetch] |
How can I have 2 or more autofill fields with typehead that calls diferents data arrays for example, one for city and other for county? |
What is the recommended approach for re-initializing typeahead to change a prefetch, a dataset, or some other property?
The text was updated successfully, but these errors were encountered: