-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
Typeahead source doesn't accept functions from HTML attributes #4888
Comments
Hey @kAlvaro, Thanks for opening this issue! Unfortunately, it looks like it fails to pass the criteria neccessary for submitting to bootstrap. The following things are currently failing:
For a full list of issue filing guidelines, please refer to the bootstrap issue filing guidelines. thanks! |
Hello, http://jsbin.com/osazuv/3/edit Basically just:
and
|
My PR fixes that: #5593 |
data source doesn't accept a function from html by design |
@fat If that design decision is not subject to change, can the documentation be fixed? |
I don't get it. Then how does one load data via ajax call? |
@slava-vishnyakov: you specify your |
@cvrebert: Thanks a lot! That works! For people looking for solution, stumbling into this thread: |
@fat The design decision makes it very clumsy in implementation of dynamically generated typeahead field. It would be clean and nice when a newly created input field use the html attribute to specify the javascript function rather than setting the source with |
I have to admit that this is a problem that I faced today. The documentation should be more clear on the implementation. I understand why having the function argument for If people were able to do that, many people could be tempted to add their typeahead handlers to the window object. The big problem here is that twitter bootstrap doesn't have any context. The only place it could find a function is from the window object. This also means that if anything overwrite the global function, In any case, having handlers in the window object isn't a good things and it's clear that twitter devs will never do it. That said, adding some context to twitter could be done and could greatly improve the api. Let say we have something like that:
and something like this is JS
the data-source would lookup the closest used context and return the function in the typeahead definition. This way, the window object is never used and every body is happy. Someone could define multiple programmatically context with sources of the same name but with different handlers. This is sure not perfect but adding some contexts to bootstrap could actually add something good. Like defining some behaviours inside js and keeping the markup as much clean as possible. |
This issue has been mooted by #7805. |
According to docs, you can use a
data-source
HTML attribute to provide either a array of strings or a function. The first option works fine:The second one doesn't. If you do e.g. this:
... the argument gets interpreted as:
The text was updated successfully, but these errors were encountered: