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

Allow 0 and false to be used in opt group values #1493

Closed
wants to merge 1 commit into from

Conversation

winzig
Copy link

@winzig winzig commented Jun 13, 2019

Refer to this discussion: #1492

@winzig
Copy link
Author

winzig commented Jun 13, 2019

Long story short: When you define optgroups, you specify values for Selectize to match a certain field against, from your options data. It uses that field to group your options together and display headers for each option group. However, there is a bug (which this fixes) whereby if your values are falsy (like zero 0 or false, things don't work.

There are two bugs in the line that is fixed:

  1. It was doing an or || test to determine if your value exists, and if your value is falsy, it's turned into empty string, which won't match your defined values.
  2. Even when the bug in Add option for confirmation on item delete. #1 is fixed, elsewhere in the code, the values are getting passed through the hash_key() function to ensure all the values get turned into strings. In this case, hash_key() turns false into '0' (zero string). Yet in this section of code that I'm fixing, the compared value was not passed through the hash_key() function, so it was comparing apples to oranges.

To fix #1, we check for existence using hasOwnProperty() instead of a simple boolean test, and to fix #2 we pass this value through hash_key() so that it matches how the values are manipulated elsewhere in Selectize.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2021

Stale pull request message

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

Successfully merging this pull request may close these issues.

None yet

1 participant