
selects_date needs to handle options similar to ActionView::Helpers::DateHelper#date_select
Reported by Peter Sumskas | November 23rd, 2008 @ 07:00 AM
I'm doing credit-card expiry date testing so I have only two fields displayed: year and month and the month is numeric, not text. That means my date_select call in my view looks like:
f.date_select :expiry_date, :use_month_numbers => true, :start_year => Time.now.year, :discard_day => true
The current selects_date doesn't handle this. I made some changes in scope.rb and have a new version of the method:
def selects_date(date_to_select, options ={})
date = date_to_select.is_a?(Date) || date_to_select.is_a?(Time) ?
date_to_select : Date.parse(date_to_select)
id_prefix = locate_id_prefix(options) do
year_field = find_field_with_id(/(.*?)_#{DATE_TIME_SUFFIXES[:year]}$/)
raise NotFoundError.new("No date fields were found") unless year_field && year_field.id =~ /(.*?)_1i/
$1
end
month = date.strftime('%B')
month = date.strftime('%b') if options[:use_short_month]
month = "#{options[:use_month_names][date.month - 1]}" if options[:use_month_names]
month = "#{date.month}" if options[:use_month_numbers]
month = "#{date.month} - #{month}" if options[:add_month_number]
selects date.year, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:year]}" unless options[:discard_year]
selects month, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:month]}" unless options[:discard_month]
selects date.day, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:day]}" unless options[:discard_day]
end
I'm pretty new to this github stuff - so if the above is something you think might be useful to include in the official code please let me know if there is anything I can do to assist.
BTW - I just noticed the above will probably have problems still if :discard_year is used (when doing the find_field_with_id bit used to get the id_prefix).
Comments and changes to this ticket
-
gaffo January 6th, 2009 @ 07:06 PM
- Tag set to featurerequest, patch
It would be prefereable if you put this on a github branch forked from webrat master called lh_71_select date.
Also some tests to show the issue will make it much more likely for someone else to come along and finish this for you.
-
Mike Breen April 12th, 2009 @ 11:24 AM
- Tag changed from featurerequest, patch to featurerequest, patch, pull, select_date
I've created a fork that allows you to use month number
select_date 4/12/2009 :use_month_numbers => true
and short monthsselect_date Apr 12, 2009 :use_short_month => true
. -
gaffo May 7th, 2009 @ 06:51 PM
- Tag changed from featurerequest, patch, pull, select_date to featurerequest, patch, pull, select_date, verify
- State changed from new to awaiting-merge
Patch looks good but have not tried it yet.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Ruby Acceptance Testing for Web applications.