This project is archived and is in readonly mode.
Date select helpers should have a :prompt option
Reported by Sam Oliver | July 7th, 2008 @ 01:13 PM
It should be possible to include a custom :prompt with the date select helpers in the same way you can include one with collection_select.
Including a prompt as the first select option is common practice when using date selects. Without this feature it's tricky to use the date select helpers if you need a custom prompt.
I've included a patch with tests and documentation. With this patch you can pass custom prompts as a hash, or pass true for a generic prompt (Day, Month, Year, Hour, Minute, Seconds).
Example:
date_select("post", "written_on", :prompt=>true)
date_select("post", "written_on", :prompt=>{:day=>'Select day', :month=>'Select month', :year=>'Select year'})
Comments and changes to this ticket
-
Joff Williams July 7th, 2008 @ 02:09 PM
+1 from me. date select is a great helper but lacks this prompt option.
-
josh October 28th, 2008 @ 04:22 PM
- State changed from new to stale
Interesting, I will have to go in after 2.2 though. Lets relook at it then.
-
grant November 3rd, 2008 @ 11:06 PM
Thanks! I'm glad I searched before writing that myself. Here's a version of the patch that applies cleanly to 2.1.2.
-
Jatinder Singh November 13th, 2008 @ 10:01 PM
+1 We should probably have a similar approach to assign different CSS class name to each select generated. or is that something possible already?
-
Martijn Vos December 16th, 2008 @ 11:10 AM
+1
Why exactly is this stale, and not already in Rails?
Also +1 on doing something similar for class name, although I think that should be a separate ticket.
-
josh December 16th, 2008 @ 04:15 PM
- State changed from stale to open
-
Pratik December 21st, 2008 @ 04:56 PM
- Assigned user set to Pratik
I like the feature/patch. I couldn't apply it cleanly on the lastest edge, could you please upload a new patch and I'll commit it.
Thanks.
-
Repository December 22nd, 2008 @ 12:14 AM
- State changed from open to resolved
(from [389534c38c3baaa63ce5cc2ba3bd169415419167]) Added prompt options to date helpers [#561 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
-
Sam Oliver December 22nd, 2008 @ 11:49 AM
This new patch uses I18n for the text in the default prompts and can be cleanly applied to edge.
-
Sven Fuchs December 22nd, 2008 @ 12:50 PM
... probably should test that the translations can be looked up though
-
Pratik December 22nd, 2008 @ 03:03 PM
- State changed from resolved to open
-
Pratik December 22nd, 2008 @ 04:38 PM
- State changed from open to resolved
Fixed in http://github.com/rails/rails/co...
-
Martijn Vos December 24th, 2008 @ 12:37 PM
add_prompts_to_date_helpers_2.3.0.diff doesn't entirely fix this issue when applied to 2.2.2. It still uses today as default value instead of nil.
In date_helper.rb, in class InstanceTag
private def default_datetime(options) return if options[:include_blank]
should be changed to
private def default_datetime(options) return if options[:include_blank] || options[:prompt]
I haven't tested against the latest edge yet, but I'd be surprised if it works properly there.
-
Sam Oliver January 2nd, 2009 @ 03:40 PM
This new patch applies the suggested change from Martijn and updates the tests to cover this issue.
-
Martijn Vos January 9th, 2009 @ 08:54 AM
Another minor but ugly issue that remains is that when I use the "year" select box, it starts at dates in the distant past. I want those to be available, but they're not the obvious choices.
I'm not sure what the best fix would be here, though. Perhaps reversing the order of the years? Or putting the prompt (with nil value) at the bottom instead of the top? How much control does a developer currently have over such things?
-
Sam Oliver January 9th, 2009 @ 11:20 AM
This is a good point but I think that it might be taking it a bit too far. You can always create your own helper to get absolute control. The :prompt option is fairly fundamental and is used in other select helpers so it's a natural inclusion. Maybe you could open a new ticket for this suggestion.
-
Sam Oliver January 9th, 2009 @ 11:26 AM
Could this ticket be re-opened as it's not quite working in edge (see my last patch)?
-
Pratik January 31st, 2009 @ 01:46 PM
- State changed from resolved to open
-
Joe F. February 12th, 2009 @ 03:26 PM
+1 - we are currently running on a patched version of Rails for this fix. We are required to use custom prompts in our date selects. Is there any way we could this fix in 2.3?
Thanks!
-
Pratik February 12th, 2009 @ 03:29 PM
- Milestone cleared.
-
Sam Oliver February 12th, 2009 @ 09:08 PM
I tested my last patch again on edge today - it still applies cleanly and the tests pass.
http://rails.lighthouseapp.com/a...
It's a small change that will hopefully close this ticket
-
Repository February 13th, 2009 @ 09:32 AM
- State changed from open to resolved
(from [f04346d8b999476113d5e5a30661e07899e3ff80]) Stops date select helpers from defaulting the selected date to today if :prompt option has been used
Signed-off-by: Michael Koziarski michael@koziarski.com [#561 state:resolved] http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 561 Date select helpers should have a :prompt option (from [389534c38c3baaa63ce5cc2ba3bd169415419167]) Added p...
- 561 Date select helpers should have a :prompt option Signed-off-by: Michael Koziarski michael@koziarski.com [#...