summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/views/issues/_attributes.html.erb2
-rw-r--r--app/views/issues/_edit.html.erb2
-rw-r--r--app/views/timelog/_form.html.erb2
-rw-r--r--lib/redmine/views/labelled_form_builder.rb9
4 files changed, 12 insertions, 3 deletions
diff --git a/app/views/issues/_attributes.html.erb b/app/views/issues/_attributes.html.erb
index f8acef58b..224960617 100644
--- a/app/views/issues/_attributes.html.erb
+++ b/app/views/issues/_attributes.html.erb
@@ -65,7 +65,7 @@
<% end %>
<% if @issue.safe_attribute? 'estimated_hours' %>
-<p><%= f.text_field :estimated_hours, :size => 3, :required => @issue.required_attribute?('estimated_hours'), :value => format_hours(@issue.estimated_hours) %> <%= l(:field_hours) %></p>
+<p><%= f.hours_field :estimated_hours, :size => 3, :required => @issue.required_attribute?('estimated_hours') %> <%= l(:field_hours) %></p>
<% end %>
<% if @issue.safe_attribute?('done_ratio') && Issue.use_field_for_done_ratio? %>
diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb
index 0a642f22c..473610cfd 100644
--- a/app/views/issues/_edit.html.erb
+++ b/app/views/issues/_edit.html.erb
@@ -14,7 +14,7 @@
<%= labelled_fields_for :time_entry, @time_entry do |time_entry| %>
<div class="splitcontent">
<div class="splitcontentleft">
- <p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time, :value => format_hours(@time_entry.hours) %> <%= l(:field_hours) %></p>
+ <p><%= time_entry.hours_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p>
</div>
<div class="splitcontentright">
<p><%= time_entry.select :activity_id, activity_collection_for_select_options %></p>
diff --git a/app/views/timelog/_form.html.erb b/app/views/timelog/_form.html.erb
index 59198d0fb..f5bc15100 100644
--- a/app/views/timelog/_form.html.erb
+++ b/app/views/timelog/_form.html.erb
@@ -18,7 +18,7 @@
</span>
</p>
<p><%= f.date_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
- <p><%= f.text_field :hours, :size => 6, :required => true, :value => format_hours(@time_entry.hours) %></p>
+ <p><%= f.hours_field :hours, :size => 6, :required => true %></p>
<p><%= f.text_field :comments, :size => 100, :maxlength => 1024 %></p>
<p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
<% @time_entry.custom_field_values.each do |value| %>
diff --git a/lib/redmine/views/labelled_form_builder.rb b/lib/redmine/views/labelled_form_builder.rb
index 965dee8c1..07805c562 100644
--- a/lib/redmine/views/labelled_form_builder.rb
+++ b/lib/redmine/views/labelled_form_builder.rb
@@ -42,6 +42,15 @@ class Redmine::Views::LabelledFormBuilder < ActionView::Helpers::FormBuilder
label_for_field(field, options) + super(field, priority_zones, options, html_options.except(:label)).html_safe
end
+ # A field for entering hours value
+ def hours_field(field, options={})
+ # display the value before type cast when the entered value is not valid
+ if @object.errors[field].blank?
+ options = options.merge(:value => format_hours(@object.send field))
+ end
+ text_field field, options
+ end
+
# Returns a label tag for the given field
def label_for_field(field, options = {})
return ''.html_safe if options.delete(:no_label)