Project

General

Profile

Feature #43589 ยป 43589-hours-field-placeholder.patch

Go MAEDA, 2026-09-20 10:58

View differences:

lib/redmine/views/labelled_form_builder.rb
50 50
  def hours_field(field, options={})
51 51
    # display the value before type cast when the entered value is not valid
52 52
    if @object.errors[field].blank?
53
      # show the placeholder only when the time span format is "minutes"
54
      placeholder = Setting.timespan_format == 'minutes' ? 'h:mm' : nil
53 55
      options = options.merge(:value => format_hours(@object.send field))
54
                       .with_defaults(:placeholder => 'h:mm')
56
                       .with_defaults(:placeholder => placeholder)
55 57
    end
56 58
    text_field field, options
57 59
  end
test/unit/lib/redmine/views/labelled_form_builder_test.rb
32 32
    entry = TimeEntry.new(:hours => '2.5')
33 33
    entry.validate
34 34

  
35
    labelled_form_for(entry) do |f|
36
      field_html = f.hours_field(:hours)
37
      assert_include 'value="2:30"', field_html
38
      assert_include 'placeholder="h:mm"', field_html
35
    with_settings :timespan_format => 'minutes' do
36
      labelled_form_for(entry) do |f|
37
        field_html = f.hours_field(:hours)
38
        assert_include 'value="2:30"', field_html
39
        assert_include 'placeholder="h:mm"', field_html
40
      end
41
    end
42
  end
43

  
44
  def test_hours_field_should_not_have_placeholder_if_timespan_format_is_decimal
45
    entry = TimeEntry.new(:hours => '2.5')
46
    entry.validate
47

  
48
    with_settings :timespan_format => 'decimal' do
49
      labelled_form_for(entry) do |f|
50
        field_html = f.hours_field(:hours)
51
        assert_include 'value="2.50"', field_html
52
        assert_not_include 'placeholder', field_html
53
      end
39 54
    end
40 55
  end
41 56

  
    (1-1/1)