##// END OF EJS Templates
Fixed: Custom field is rendered, even if its value is empty (for multiple) (#18654)....
Jean-Philippe Lang -
r13482:a18c719fcc9c
parent child
Show More
@@ -117,6 +117,17 module CustomFieldsHelper
117 Redmine::FieldFormat.as_select(custom_field.class.customized_class.name)
117 Redmine::FieldFormat.as_select(custom_field.class.customized_class.name)
118 end
118 end
119
119
120 # Yields the given block for each custom field value of object that should be
121 # displayed, with the custom field and the formatted value as arguments
122 def render_custom_field_values(object, &block)
123 object.visible_custom_field_values.each do |custom_value|
124 formatted = show_value(custom_value)
125 if formatted.present?
126 yield custom_value.custom_field, formatted
127 end
128 end
129 end
130
120 # Renders the custom_values in api views
131 # Renders the custom_values in api views
121 def render_api_custom_values(custom_values, api)
132 def render_api_custom_values(custom_values, api)
122 api.array :custom_fields do
133 api.array :custom_fields do
@@ -31,10 +31,8
31 <li><span class="label"><%=l(:label_subproject_plural)%>:</span>
31 <li><span class="label"><%=l(:label_subproject_plural)%>:</span>
32 <%= @subprojects.collect{|p| link_to p, project_path(p)}.join(", ").html_safe %></li>
32 <%= @subprojects.collect{|p| link_to p, project_path(p)}.join(", ").html_safe %></li>
33 <% end %>
33 <% end %>
34 <% @project.visible_custom_field_values.each do |custom_value| %>
34 <% render_custom_field_values(@project) do |custom_field, formatted| %>
35 <% if !custom_value.value.blank? %>
35 <li><span class="label"><%= custom_field.name %>:</span> <%= formatted %></li>
36 <li><span class="label"><%=h custom_value.custom_field.name %>:</span> <%=h show_value(custom_value) %></li>
37 <% end %>
38 <% end %>
36 <% end %>
39 </ul>
37 </ul>
40
38
@@ -7,10 +7,8
7 <p><%=h version.description %></p>
7 <p><%=h version.description %></p>
8 <% if version.custom_field_values.any? %>
8 <% if version.custom_field_values.any? %>
9 <ul>
9 <ul>
10 <% version.custom_field_values.each do |custom_value| %>
10 <% render_custom_field_values(version) do |custom_field, formatted| %>
11 <% if custom_value.value.present? %>
11 <li><span class="label"><%= custom_field.name %>:</span> <%= formatted %></li>
12 <li><%=h custom_value.custom_field.name %>: <%=h show_value(custom_value) %></li>
13 <% end %>
14 <% end %>
12 <% end %>
15 </ul>
13 </ul>
16 <% end %>
14 <% end %>
@@ -351,6 +351,18 class ProjectsControllerTest < ActionController::TestCase
351 assert_select 'li', :text => /Development status/, :count => 0
351 assert_select 'li', :text => /Development status/, :count => 0
352 end
352 end
353
353
354 def test_show_should_not_display_blank_custom_fields_with_multiple_values
355 f1 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Foo Bar), :multiple => true
356 f2 = ProjectCustomField.generate! :field_format => 'list', :possible_values => %w(Baz Qux), :multiple => true
357 project = Project.generate!(:custom_field_values => {f2.id.to_s => %w(Qux)})
358
359 get :show, :id => project.id
360 assert_response :success
361
362 assert_select 'li', :text => /#{f1.name}/, :count => 0
363 assert_select 'li', :text => /#{f2.name}/
364 end
365
354 def test_show_should_not_fail_when_custom_values_are_nil
366 def test_show_should_not_fail_when_custom_values_are_nil
355 project = Project.find_by_identifier('ecookbook')
367 project = Project.find_by_identifier('ecookbook')
356 project.custom_values.first.update_attribute(:value, nil)
368 project.custom_values.first.update_attribute(:value, nil)
General Comments 0
You need to be logged in to leave comments. Login now