-
Notifications
You must be signed in to change notification settings - Fork 176
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
Allow null or empty string in select options #42
Conversation
Hi @jr314159 - can you give more details on the bug or a use case because I think what you are describing is correct. |
Sure. We are using stickit with <select> elements. When we configure stickit to bind to this element, we pass it an array of label, value pairs. We want the first option in our list to have a label but have an empty or null value like so: <option value="">Choose an option </option> This was not working with stickit because when we pass the label value pair ['', 'Choose an option'] in our selectConfig, it runs evaluatePath, and the empty string evaluates to false, so it returns the entire javascript object instead of just the value. Then when we did model.get('foo') it would return an object instead of '' as it should have. |
@jr314159, can you give an example of the actual options collection/array you are working with and the selectOptions, please? |
Here is an example piece of the bindings object we pass into stickit():
|
@jr314159 - thanks for the example. I merged this in a little differently, since really what we are after is preserving non-null values. Get the latest from master and try it on your codebase. Thanks for reporting. |
Awesome, thanks. |
What was the fix? I'm on ver 0.6.3 and I'm having the same problem when I create a
In this case, selecting "None" ends up saving the object {label: "None", value: null} on the model. |
Ah, I see it now. Any chance we can get it to save NULL values? I'm serializing my models and persisting them to the server and it would be great to be able to send NULL as a value. |
My workaround for now is to define an |
The logic in evaluatePath seems to have a problem where a select option with null or "" is causing the entire object to be assigned to the element's data instead of just the value. This seems to fix things.