Skip to content
This repository has been archived by the owner on Jun 21, 2018. It is now read-only.

Commit

Permalink
* Selecting dates in April 2007 doesn't highlight day
Browse files Browse the repository at this point in the history
* Selecting 29 February 2008 returns 1 March 2008

* options[:format] needs to be purged

git-svn-id: https://calendardateselect.googlecode.com/svn/trunk@65 4972a71b-da31-0410-b7dd-373b726a5e75
  • Loading branch information
timcharper committed Jun 22, 2007
1 parent 8c4ed4a commit 820ab22
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
28 changes: 19 additions & 9 deletions lib/calendar_date_select.rb
Expand Up @@ -3,6 +3,9 @@ module FormHelper
def calendar_date_select_tag( name, value = nil, options = {})
calendar_options = calendar_date_select_process_options(options)
value = (value.strftime(options[:format]) rescue "") if (value.respond_to?("strftime"))

options.delete(:format)

options[:id] ||= name

if calendar_options[:embedded]
Expand All @@ -25,7 +28,7 @@ def calendar_date_select_process_options(options)
calendar_options[:embedded] = options.delete(:embedded) ? true : false
calendar_options[:year_range] = options.delete(:year_range) || 10

options[:format]||="%B %d, %Y" + (calendar_options[:time] ? " %I:%M %p" : '')
options[:format] ||= "%B %d, %Y" + (calendar_options[:time] ? " %I:%M %p" : '')

calendar_options
end
Expand All @@ -42,15 +45,22 @@ def calendar_date_select(object, method, options={})

value = obj.send(method).strftime(options[:format]) rescue ""

options[:id]||="#{object}#{obj.id ? ('_'+obj.id.to_s) : ''}_#{method}"

out = text_field(object, method, options.merge('value' => value))
out << " "
options.delete(:format)

out << image_tag("calendar.gif",
:onclick => "new CalendarDateSelect('#{options[:id]}', #{options_for_javascript(calendar_options)} );",
:id => "_#{options[:id]}_link",
:style => 'border:0px; cursor:pointer;')
options[:id]||="#{object}#{obj.id ? ('_'+obj.id.to_s) : ''}_#{method}"

if calendar_options[:embedded]
out = hidden_field(object, method, options.merge('value' => value))
out << javascript_tag("new CalendarDateSelect('#{options[:id]}', #{options_for_javascript(calendar_options)} ); ")
else
out = text_field(object, method, options.merge('value' => value))
out << " "

out << image_tag("calendar.gif",
:onclick => "new CalendarDateSelect('#{options[:id]}', #{options_for_javascript(calendar_options)} );",
:id => "_#{options[:id]}_link",
:style => 'border:0px; cursor:pointer;')
end

if obj.respond_to?(:errors) and obj.errors.on(method) then
ActionView::Base.field_error_proc.call(out, nil) # What should I pass ?
Expand Down
7 changes: 4 additions & 3 deletions public/javascripts/calendar_date_select.js
@@ -1,4 +1,4 @@
// CalendarDateSelect version 1.4- a small prototype based date picker
// CalendarDateSelect version 1.5.1 - a small prototype based date picker
// Questions, comments, bugs? - email the Author - Tim Harper <"timseeharper@gmail.seeom".gsub("see", "c")>
Element.addMethods({
purgeChildren: function(element) { $A(element.childNodes).each(function(e){$(e).remove();}); },
Expand Down Expand Up @@ -27,7 +27,7 @@ Date.prototype.getPaddedMinutes = function() { return Date.padded2(this.getMinut
Date.prototype.getAMPMHour = function() { hour=this.getHours(); return (hour == 0) ? 12 : (hour > 12 ? hour - 12 : hour ) }
Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "AM" : "PM"; }
Date.prototype.stripTime = function() { return new Date(this.getFullYear(), this.getMonth(), this.getDate());};
Date.prototype.daysDistance = function(compare_date) { return (compare_date - this) / Date.one_day; };
Date.prototype.daysDistance = function(compare_date) { return Math.round((compare_date - this) / Date.one_day); };
Date.prototype.toFormattedString = function(include_time){
str = Date.months[this.getMonth()] + " " + this.getDate() + ", " + this.getFullYear();

Expand Down Expand Up @@ -298,9 +298,10 @@ CalendarDateSelect.prototype = {
updateSelectedDate:function(parts) {
if (parts.day) {
this.selection_made = true;
for (x=0; x<=1; x++) {
this.selected_date.setDate(parts.day);
this.selected_date.setMonth(parts.month);
this.selected_date.setYear(parts.year);
this.selected_date.setYear(parts.year);}
}

if (parts.hour) this.selected_date.setHours(parts.hour);
Expand Down

0 comments on commit 820ab22

Please sign in to comment.