diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index abf925e1..41fd5dbe 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -36,8 +36,7 @@ module CustomFieldsHelper field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) case field_format.try(:edit_as) when "date" - text_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) + - calendar_for(field_id) + date_field_tag(field_name, custom_value.value, :id => field_id, :size => 10) when "text" text_area_tag(field_name, custom_value.value, :id => field_id, :rows => 3, :style => 'width:90%') when "bool" @@ -71,8 +70,7 @@ module CustomFieldsHelper field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format) case field_format.try(:edit_as) when "date" - text_field_tag(field_name, '', :id => field_id, :size => 10) + - calendar_for(field_id) + date_field_tag(field_name, '', :id => field_id, :size => 10) when "text" text_area_tag(field_name, '', :id => field_id, :rows => 3, :style => 'width:90%') when "bool" diff --git a/app/views/issue_moves/new.rhtml b/app/views/issue_moves/new.rhtml index f1327ad7..bf0bf698 100644 --- a/app/views/issue_moves/new.rhtml +++ b/app/views/issue_moves/new.rhtml @@ -46,12 +46,12 @@

- <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %> + <%= date_field_tag 'start_date', '', :size => 10 %>

- <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %> + <%= date_field_tag 'due_date', '', :size => 10 %>

diff --git a/app/views/issues/_attributes.rhtml b/app/views/issues/_attributes.rhtml index 499537ef..9fe7afc3 100644 --- a/app/views/issues/_attributes.rhtml +++ b/app/views/issues/_attributes.rhtml @@ -31,8 +31,8 @@
-

<%= f.text_field :start_date, :size => 10, :disabled => !@issue.leaf? %><%= calendar_for('issue_start_date') if @issue.leaf? %>

-

<%= f.text_field :due_date, :size => 10, :disabled => !@issue.leaf? %><%= calendar_for('issue_due_date') if @issue.leaf? %>

+

<%= f.date_field :start_date, :size => 10, :disabled => !@issue.leaf? %>

+

<%= f.date_field :due_date, :size => 10, :disabled => !@issue.leaf? %>

<%= f.text_field :estimated_hours, :size => 3, :disabled => !@issue.leaf? %> <%= l(:field_hours) %>

<% if @issue.leaf? && Issue.use_field_for_done_ratio? %>

<%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %>

diff --git a/app/views/issues/bulk_edit.rhtml b/app/views/issues/bulk_edit.rhtml index 61bd7e4a..0b2897e2 100644 --- a/app/views/issues/bulk_edit.rhtml +++ b/app/views/issues/bulk_edit.rhtml @@ -65,11 +65,11 @@ <% end %>

- <%= text_field_tag 'issue[start_date]', '', :size => 10 %><%= calendar_for('issue_start_date') %> + <%= date_field_tag 'issue[start_date]', '', :size => 10 %>

- <%= text_field_tag 'issue[due_date]', '', :size => 10 %><%= calendar_for('issue_due_date') %> + <%= date_field_tag 'issue[due_date]', '', :size => 10 %>

<% if Issue.use_field_for_done_ratio? %>

diff --git a/app/views/queries/_filters.rhtml b/app/views/queries/_filters.rhtml index b5a018f0..f64b4fb9 100644 --- a/app/views/queries/_filters.rhtml +++ b/app/views/queries/_filters.rhtml @@ -125,8 +125,8 @@ Event.observe(document,"dom:loaded", apply_filters_observer); <%= link_to_function image_tag('bullet_toggle_plus.png'), "toggle_multi_select('values_#{field}_1');", :style => "vertical-align: bottom;" %> <% when :date, :date_past %> - <%= text_field_tag "v[#{field}][]", query.value_for(field), :size => 10, :class => "values_#{field}", :id => "values_#{field}_1" %> <%= calendar_for "values_#{field}_1" %> - <%= text_field_tag "v[#{field}][]", query.value_for(field, 1), :size => 10, :class => "values_#{field}", :id => "values_#{field}_2" %> <%= calendar_for "values_#{field}_2" %> + <%= date_field_tag "v[#{field}][]", query.value_for(field), :size => 10, :class => "values_#{field}", :id => "values_#{field}_1" %> + <%= date_field_tag "v[#{field}][]", query.value_for(field, 1), :size => 10, :class => "values_#{field}", :id => "values_#{field}_2" %> <%= text_field_tag "v[#{field}][]", query.value_for(field), :size => 3, :class => "values_#{field}" %> <%= l(:label_day_plural) %> <% when :string, :text %> <%= text_field_tag "v[#{field}][]", query.value_for(field), :class => "values_#{field}", :id => "values_#{field}", :size => 30 %> diff --git a/app/views/timelog/_date_range.rhtml b/app/views/timelog/_date_range.rhtml index f42069cc..42ccad6e 100644 --- a/app/views/timelog/_date_range.rhtml +++ b/app/views/timelog/_date_range.rhtml @@ -18,13 +18,11 @@ l(:label_date_from_to, :start => ( label_tag("from", l(:description_date_from), :class => "hidden-for-sighted") + - text_field_tag('from', @from, :size => 10, :disabled => !@free_period) + - calendar_for('from') + date_field_tag('from', @from, :size => 10, :disabled => !@free_period) ), :end => ( label_tag("to", l(:description_date_to), :class => "hidden-for-sighted") + - text_field_tag('to', @to, :size => 10, :disabled => !@free_period) + - calendar_for('to') + date_field_tag('to', @to, :size => 10, :disabled => !@free_period) ) ) %> diff --git a/app/views/timelog/edit.rhtml b/app/views/timelog/edit.rhtml index 5ab97746..a9580ca6 100644 --- a/app/views/timelog/edit.rhtml +++ b/app/views/timelog/edit.rhtml @@ -11,7 +11,7 @@

<%= f.text_field :issue_id, :size => 6 %> <%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %>

-

<%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %>

+

<%= f.date_field :spent_on, :size => 10, :required => true %>

<%= f.text_field :hours, :size => 6, :required => true %>

<%= f.text_field :comments, :size => 100 %>

<%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %>

diff --git a/app/views/versions/_form.rhtml b/app/views/versions/_form.rhtml index c151185b..29ce90db 100644 --- a/app/views/versions/_form.rhtml +++ b/app/views/versions/_form.rhtml @@ -5,8 +5,8 @@

<%= f.text_field :description, :size => 60 %>

<%= f.select :status, Version::VERSION_STATUSES.collect {|s| [l("version_status_#{s}"), s]} %>

<%= f.text_field :wiki_page_title, :label => :label_wiki_page, :size => 60, :disabled => @project.wiki.nil? %>

-

<%= f.text_field :start_date, :size => 10 %><%= calendar_for('version_start_date') %>

-

<%= f.text_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %>

+

<%= f.date_field :start_date, :size => 10 %>

+

<%= f.date_field :effective_date, :size => 10 %>

<%= f.select :sharing, @version.allowed_sharings.collect {|v| [format_version_sharing(v), v]} %>

<% @version.custom_field_values.each do |value| %> diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb index e51e30d2..b26a45d2 100644 --- a/config/initializers/10-patches.rb +++ b/config/initializers/10-patches.rb @@ -78,6 +78,53 @@ module ActionView end end end + + module FormHelper + # Returns an input tag of the "date" type tailored for accessing a specified attribute (identified by +method+) on an object + # assigned to the template (identified by +object+). Additional options on the input tag can be passed as a + # hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example + # shown. + # + # ==== Examples + # date_field(:user, :birthday, :size => 20) + # # => + # + # date_field(:user, :birthday, :class => "create_input") + # # => + # + # NOTE: This will be part of rails 4.0, the monkey patch can be removed by then. + def date_field(object_name, method, options = {}) + InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("date", options) + end + end + + # As ActionPacks metaprogramming will already have happened when we're here, + # we have to tell the FormBuilder about the above date_field ourselvse + # + # NOTE: This can be remove when the above ActionView::Helpers::FormHelper#date_field is removed + class FormBuilder + self.field_helpers << "date_field" + + def date_field(method, options = {}) + @template.date_field(@object_name, method, objectify_options(options)) + end + end + + module FormTagHelper + # Creates a date form input field. + # + # ==== Options + # * Creates standard HTML attributes for the tag. + # + # ==== Examples + # date_field_tag 'meeting_date' + # # => + # + # NOTE: This will be part of rails 4.0, the monkey patch can be removed by then. + def date_field_tag(name, value = nil, options = {}) + text_field_tag(name, value, options.stringify_keys.update("type" => "date")) + end + end end end