]> source.dussan.org Git - redmine.git/commitdiff
Show the entered value when it's not valid (#23996).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 18 Nov 2016 14:17:11 +0000 (14:17 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 18 Nov 2016 14:17:11 +0000 (14:17 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@15971 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/views/issues/_attributes.html.erb
app/views/issues/_edit.html.erb
app/views/timelog/_form.html.erb
lib/redmine/views/labelled_form_builder.rb

index f8acef58bd58b17a0520fa79234d0926cb1272a9..224960617f1e73b452878ea6478a6f9a8ba2ee86 100644 (file)
@@ -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? %>
index 0a642f22c9be2816bf32b5fc393a714d1be51213..473610cfd18513963349aff0cd00e9b5e64928bf 100644 (file)
@@ -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>
index 59198d0fb682889484a73b704aaf0bc96acf1ad0..f5bc15100c5e4db34bc9894f8d51a285bd9ee4d5 100644 (file)
@@ -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| %>
index 965dee8c1f838bb5ba11f2f837125e194bd18d7d..07805c562da3b9ca9905eadd2d0b6ebc6c7bda90 100644 (file)
@@ -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)