Skip to content

Fixes issue with "null" being displayed in drop down#70

Closed
macfanatic wants to merge 1 commit intogregschmit:masterfrom
macfanatic:mb-fix-null-display
Closed

Fixes issue with "null" being displayed in drop down#70
macfanatic wants to merge 1 commit intogregschmit:masterfrom
macfanatic:mb-fix-null-display

Conversation

@macfanatic
Copy link

All the code checks for presence, but the db stores the string “null”.

For backwards compatibility, the fix could be to update all the checks
to ensure that “null” is considered a blank string essentially, but for
our project adding this for the first time we decided to just store nil
in the database as the proper solution.

@naomiaro
Copy link
Contributor

Nice, I was noticing this was an issue for me as well. Maybe you can update the tests to match this change here to get it merged.
https://github.com/GetJobber/recurring_select/blob/master/spec/app/helpers/recurring_select_helper_spec.rb

All the code checks for presence, but the db stores the string “null”.

For backwards compatibility, the fix could be to update all the checks
to ensure that “null” is considered a blank string essentially, but for
our project adding this for the first time we decided to just store nil
in the database as the proper solution.
@benzittlau
Copy link
Contributor

@macfanatic First of all, thanks for the contribution and sorry for the slow response.

Looking at this, I believe the reason this was done using the "null" string is that in Rails if you pass nil as the selected option to options_for_select it doesn't look for an option with a blank value to mark as selected, but instead ignores it like there wasn't a selected option. This means that if you have a blank value anywhere in the options that isn't the first option, then the select element won't reflect the selected option.

I think the better way to address this would be to find any places that aren't correctly identifying "null" and fix those. I wasn't able to find any with a quick survey, but if you could make a PR fixing this from that angle I'd be happy to merge that in.

@benzittlau benzittlau closed this Dec 18, 2014
@nitsujri
Copy link

@benzittlau Thanks for this.

What is the recommended way to handle the null being displayed in the select?

@TangMonk
Copy link

@benzittlau Thanks

How to render a exist model with select_recurring when the string is "null"?

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

Successfully merging this pull request may close these issues.

5 participants