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 date inputs to default to blank #152
Comments
I have pushed up a fix for this in http://github.com/justinfrench/formtastic/commit/7b947cb528e1e13c1f62da23be07ba310ff2c1bd. I only partially implemented Adam's suggested fix. We now only fallback to Time.now if options[:selected] is not present, but I didn't think it was necessary to force a blank option when selected is nil — that should be the form author's choice. Closing for now, will be in next gem. |
Shouldnt options[:selected] override the value returned by the method on the object?. With this fix that wont happen for options[:selected]=nil since its OR'd with the value returned |
So, let me get this straight:
Is that the use cases I need to check/spec? |
That sounds OK to me. For the 4th one, you may want it to select Time.now. That's the old default behavior and I imagine some people are relying upon that behavior. The main thing is to honor whatever value is passed for the :selected option. The default behavior (when no :selected option is provided) can go either way--just make sure it's documented. |
I believe the problem here is that :selected is being used to set the :default behavior, when the two typically have different meanings. :selected is typically to override what would normally be set, while :default would be to set what is selected when nothing is set. Maybe there should be an option to set :default (which would default to Time.now if not set). Then it would be
|
Sigh good advice. I'm a bit shitty about this because the only reason I'm supporting it is because Rails does. I think this stuff should all be done when initializing the model. Anyway, thanks, looks like we have the use cases sorted, I'll go re-write about 50 lines of specs for three lines of code changes ;) |
We've had more discussion in the google group, I'm leaning towards :default instead of :selected. http://groups.google.com.au/group/formtastic/msg/ab160fb984ba1529 |
Ok, I have a patch in the "datetime" branch, would love some code review and real-world testing before it goes into master: http://github.com/justinfrench/formtastic/tree/datetime |
A few people have reviewed this, closing. |
…t to nil): * added failing specs * changed date_or_datetime_input to only fallback to Time.now when options[:selected] is not present
…avour of a deprecated :selected option (issue formtastic#152): * if the object has a value, we should pre-select that at all times, ignoring the :default option * if the object has no value, and :default is provided as a Date/Time then :default should be pre-selected * if the object has no value, and :default is provided as nil then no option should be pre-selected (it will default to the first) * if the object has no value, and :default is not provided then fallback to Time.now (or perhaps a configurable default) * :selected invokes a deprecation warning, but is an alias of :default * it's not a real deprecation, as the behaviour has changed with all the bugs and half-fixes
Currently there is no way to make a date input default to blank. You can pass a default using the :selected option, but it only uses this if ruby evaluates it to true. Otherwise if uses Time.now. So, if you pass :selected => nil, ruby considers this false and Time.now is used.
See discussion at:
http://groups.google.com.au/group/formtastic/browse_thread/thread/5ffd565ddcad412f
The text was updated successfully, but these errors were encountered: