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

Example of create? #992

Open
brylie opened this issue Jan 26, 2016 · 5 comments
Open

Example of create? #992

brylie opened this issue Jan 26, 2016 · 5 comments

Comments

@brylie
Copy link

@brylie brylie commented Jan 26, 2016

I am having difficulty understanding how to use the create function callback. I have found one StackOverflow post describing create callback functions, but am not able to get the create callback to work, as the tag is not inserted back into the select array.

Is there a functional example of how to use the create method with a callback function?

@chickenboot
Copy link

@chickenboot chickenboot commented Nov 27, 2016

I found this while I was having similar issues: I have a selectize attached to a pre-populated select input, but I wanted to add a create method. I was able to create the item but it wasn't being added to the control.

I was able to fix this by adding a return undefined; to my create: function(input, callback) section (using the callback to set value and text correctly).

@brylie
Copy link
Author

@brylie brylie commented Nov 28, 2016

Ah, tricky. Thanks for the feedback.

I basically ended up removing selectize.js, as it was adding unnecessary complexity for the feature - a basic select box ended up being sufficient.

@chickenboot
Copy link

@chickenboot chickenboot commented Nov 28, 2016

Ah fair enough - I thought I'd comment for posterity in case anyone else came this way.

Thinking about it a little more last night, I think this is most likely due to me using coffeescript: by default CS returns the last statement (like Ruby), and I think if I were using plain javascript I wouldn't have had this problem. In the selectize code there is a check for the return value of the create function: if you don't return anything then this would just work, but obviously in coffeescript it does it behind the scenes which caused my confusion.

@zinkkrysty
Copy link

@zinkkrysty zinkkrysty commented Nov 29, 2016

I also had hard time figuring this out, I'm using coffeescript so returning something at the end of each function is normal behavior. Could this be avoided by checking if a callback is specified in the function arguments? Or by always adding/updating the item when the callback is called?

I'm figuring the latter is also useful to allow the action to persist on the client, and update once we got the result from the server (such as adding important information as resource ID)

@qbonnard
Copy link

@qbonnard qbonnard commented Jun 13, 2018

Thanks @chickenboot I also had this (coffee-related) issue
As an alternative to @zinkkrysty 's suggestions: how about just documenting it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.