Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

initSelection should use a callback, not return for AJAX #158

Closed
ProLoser opened this Issue Jun 26, 2012 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

ProLoser commented Jun 26, 2012

Lets say we are using ajax, which gets an array of objects.

Lets also say that when the form loads, we have a simple input with a string value of the id or comma-separated ids.

When select loads, we should be able to query the backend for the missing details to retrieve the labels and other template information when select2 loads. We would then return (or pass) this ajax response to select2 like normal.

Need to pass a callback method (this can be additional/optional) to our initSelection method that we are permitted to call, passing the data to after our AJAX is complete. You could check to see if initSelection() returns anything, and if so behave the same as it already does. However, if nothing is returned, then wait for the callback to be fired.

Not that handling both methods may not be ideal however in order to minimize confusion AND because coffeescript always returns the last line executed. You could simply note this on the docs however.

Contributor

ivaynberg commented Jun 28, 2012

fixed with #168

@ivaynberg ivaynberg closed this Jun 28, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment