Add date_field and date_field_tag form helpers #817
This commit is contained in:
parent
7437eaea53
commit
5cefd6a425
|
@ -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"
|
||||
|
|
|
@ -46,12 +46,12 @@
|
|||
<div class="splitcontentright">
|
||||
<p>
|
||||
<label for='start_date'><%= l(:field_start_date) %></label>
|
||||
<%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %>
|
||||
<%= date_field_tag 'start_date', '', :size => 10 %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for='due_date'><%= l(:field_due_date) %></label>
|
||||
<%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %>
|
||||
<%= date_field_tag 'due_date', '', :size => 10 %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
</div>
|
||||
|
||||
<div class="splitcontentright">
|
||||
<p><%= f.text_field :start_date, :size => 10, :disabled => !@issue.leaf? %><%= calendar_for('issue_start_date') if @issue.leaf? %></p>
|
||||
<p><%= f.text_field :due_date, :size => 10, :disabled => !@issue.leaf? %><%= calendar_for('issue_due_date') if @issue.leaf? %></p>
|
||||
<p><%= f.date_field :start_date, :size => 10, :disabled => !@issue.leaf? %></p>
|
||||
<p><%= f.date_field :due_date, :size => 10, :disabled => !@issue.leaf? %></p>
|
||||
<p><%= f.text_field :estimated_hours, :size => 3, :disabled => !@issue.leaf? %> <%= l(:field_hours) %></p>
|
||||
<% if @issue.leaf? && Issue.use_field_for_done_ratio? %>
|
||||
<p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
|
||||
|
|
|
@ -65,11 +65,11 @@
|
|||
<% end %>
|
||||
<p>
|
||||
<label for='issue_start_date'><%= l(:field_start_date) %></label>
|
||||
<%= text_field_tag 'issue[start_date]', '', :size => 10 %><%= calendar_for('issue_start_date') %>
|
||||
<%= date_field_tag 'issue[start_date]', '', :size => 10 %>
|
||||
</p>
|
||||
<p>
|
||||
<label for='issue_due_date'><%= l(:field_due_date) %></label>
|
||||
<%= text_field_tag 'issue[due_date]', '', :size => 10 %><%= calendar_for('issue_due_date') %>
|
||||
<%= date_field_tag 'issue[due_date]', '', :size => 10 %>
|
||||
</p>
|
||||
<% if Issue.use_field_for_done_ratio? %>
|
||||
<p>
|
||||
|
|
|
@ -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;" %>
|
||||
</span>
|
||||
<% when :date, :date_past %>
|
||||
<span class="span_values_<%= field %>"><%= text_field_tag "v[#{field}][]", query.value_for(field), :size => 10, :class => "values_#{field}", :id => "values_#{field}_1" %> <%= calendar_for "values_#{field}_1" %></span>
|
||||
<span class="span_values_<%= field %>"><%= text_field_tag "v[#{field}][]", query.value_for(field, 1), :size => 10, :class => "values_#{field}", :id => "values_#{field}_2" %> <%= calendar_for "values_#{field}_2" %></span>
|
||||
<span class="span_values_<%= field %>"><%= date_field_tag "v[#{field}][]", query.value_for(field), :size => 10, :class => "values_#{field}", :id => "values_#{field}_1" %></span>
|
||||
<span class="span_values_<%= field %>"><%= date_field_tag "v[#{field}][]", query.value_for(field, 1), :size => 10, :class => "values_#{field}", :id => "values_#{field}_2" %></span>
|
||||
<span class="span_values_<%= field %>"><%= text_field_tag "v[#{field}][]", query.value_for(field), :size => 3, :class => "values_#{field}" %> <%= l(:label_day_plural) %></span>
|
||||
<% when :string, :text %>
|
||||
<span class="span_values_<%= field %>"><%= text_field_tag "v[#{field}][]", query.value_for(field), :class => "values_#{field}", :id => "values_#{field}", :size => 30 %></span>
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
)
|
||||
%>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<div class="box">
|
||||
<p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p>
|
||||
<p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
|
||||
<p><%= f.date_field :spent_on, :size => 10, :required => true %></p>
|
||||
<p><%= f.text_field :hours, :size => 6, :required => true %></p>
|
||||
<p><%= f.text_field :comments, :size => 100 %></p>
|
||||
<p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
<p><%= f.text_field :description, :size => 60 %></p>
|
||||
<p><%= f.select :status, Version::VERSION_STATUSES.collect {|s| [l("version_status_#{s}"), s]} %></p>
|
||||
<p><%= f.text_field :wiki_page_title, :label => :label_wiki_page, :size => 60, :disabled => @project.wiki.nil? %></p>
|
||||
<p><%= f.text_field :start_date, :size => 10 %><%= calendar_for('version_start_date') %></p>
|
||||
<p><%= f.text_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %></p>
|
||||
<p><%= f.date_field :start_date, :size => 10 %></p>
|
||||
<p><%= f.date_field :effective_date, :size => 10 %></p>
|
||||
<p><%= f.select :sharing, @version.allowed_sharings.collect {|v| [format_version_sharing(v), v]} %></p>
|
||||
|
||||
<% @version.custom_field_values.each do |value| %>
|
||||
|
|
|
@ -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)
|
||||
# # => <input type="date" id="user_birthday" name="user[birthday]" size="20" value="#{@user.birthday}" />
|
||||
#
|
||||
# date_field(:user, :birthday, :class => "create_input")
|
||||
# # => <input type="date" id="user_birthday" name="user[birthday]" value="#{@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'
|
||||
# # => <input id="meeting_date" name="meeting_date" type="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
|
||||
|
||||
|
|
Loading…
Reference in New Issue