Feature #43589 ยป 43589-hours-field-placeholder.patch
| lib/redmine/views/labelled_form_builder.rb | ||
|---|---|---|
|
def hours_field(field, options={})
|
||
|
# display the value before type cast when the entered value is not valid
|
||
|
if @object.errors[field].blank?
|
||
|
# show the placeholder only when the time span format is "minutes"
|
||
|
placeholder = Setting.timespan_format == 'minutes' ? 'h:mm' : nil
|
||
|
options = options.merge(:value => format_hours(@object.send field))
|
||
|
.with_defaults(:placeholder => 'h:mm')
|
||
|
.with_defaults(:placeholder => placeholder)
|
||
|
end
|
||
|
text_field field, options
|
||
|
end
|
||
| test/unit/lib/redmine/views/labelled_form_builder_test.rb | ||
|---|---|---|
|
entry = TimeEntry.new(:hours => '2.5')
|
||
|
entry.validate
|
||
|
labelled_form_for(entry) do |f|
|
||
|
field_html = f.hours_field(:hours)
|
||
|
assert_include 'value="2:30"', field_html
|
||
|
assert_include 'placeholder="h:mm"', field_html
|
||
|
with_settings :timespan_format => 'minutes' do
|
||
|
labelled_form_for(entry) do |f|
|
||
|
field_html = f.hours_field(:hours)
|
||
|
assert_include 'value="2:30"', field_html
|
||
|
assert_include 'placeholder="h:mm"', field_html
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_hours_field_should_not_have_placeholder_if_timespan_format_is_decimal
|
||
|
entry = TimeEntry.new(:hours => '2.5')
|
||
|
entry.validate
|
||
|
with_settings :timespan_format => 'decimal' do
|
||
|
labelled_form_for(entry) do |f|
|
||
|
field_html = f.hours_field(:hours)
|
||
|
assert_include 'value="2.50"', field_html
|
||
|
assert_not_include 'placeholder', field_html
|
||
|
end
|
||
|
end
|
||
|
end
|
||