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

[Proposal] Use dataSource to store object items and events #33

Closed
gperdomor opened this issue Nov 26, 2014 · 2 comments
Closed

[Proposal] Use dataSource to store object items and events #33

gperdomor opened this issue Nov 26, 2014 · 2 comments

Comments

@gperdomor
Copy link

Hi, this plugin is awesome, but i think would be better if offers the possibility to have a dataSource or something like that, why?, keep reading :D...

I'm working on a project using this plugin, but in some cases, i need execute some function on select event, the problem is when that function needs a field of the object represented in the options list, for example, in my project, the ajax request return a client list, where the client's id is the 'value' and the client's name is the 'text' shown on the options list of the plugin, i need execute a function for validate or show something using/depending of another field of the client, like status or email (any field can be used), but i can't access to these fields.

My proposal is add a 'item' parameter on the json returned in the ajax request, and that field contains the complete object (or extra fields if the object have too many fields and not all of them are needed on the client-side) represented in the ajax request, and add a method like getItem(), which return the item selected instead of the value as the "val()" method does.

Twitter Typeahead plugin have a event ('typeahead:selected') which is fired when the user select an item, and the function of this event has two parameters, the event himself and the item with the object. Would be nice have something like that here....

this is my json proposal:

[
    {
        item: object
        value: 'string', 
        text: 'string',
        class: 'string',
        disable: false, 
        divider: true,
        data: {
            divider: true,
            subtext: 'string',
            icon: 'class-name', // Icon class name ex: icon-glass
            content: '<div class="custom-class">my value label</div>',
        }
    }
    ....
]

Would be nice too, have events like onOpen, onClose, onSelect, beforeRequest, afterRequest, etc 👍

@truckingsim
Copy link
Owner

So anything that happens after the options are generated are handled by bootstrap-select not this plugin. Once we generate the options are hands are off for any select, click, etc... events. We don't have any control over the return value on select.

As for your last sentence:

  • onOpen - bootstrap-select would need to implement this
  • onClose - bootstrap-select would need to implement this
  • onSelect - bootstrap-select would need to implement this
  • afterRequest - preprocessData option is called immediately after any ajax request. The first parameter is the raw data from your server and you should return the json in the way the plugin expects (like you have above).

For beforeReqeuest we don't have a specific option or even for that, but assuming you are trying to manipulate you could use the ajax options with data being a function. This is something we added so that the data sent to the server could be generated dynamically. The only caveat is that whatever key you want to have the value typed in the search box needs to have a value of {{{q}}}. We have an example of this in the usage example at the bottom of the read me.

@truckingsim
Copy link
Owner

Bootstrap select has added events I don't think there's anything else to add here closing this.

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

2 participants