]> source.dussan.org Git - redmine.git/commitdiff
Add class 'error' to custom fields with validation errors (#32764, #34580).
authorGo MAEDA <maeda@farend.jp>
Mon, 11 Jan 2021 12:26:44 +0000 (12:26 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 11 Jan 2021 12:26:44 +0000 (12:26 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@20710 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/custom_fields_helper.rb
app/models/custom_field_value.rb
app/models/issue.rb
test/functional/issues_controller_test.rb

index 41b20c46a58ba56a948fe11590444e39f98b9bdf..2845c86734adc5b4e049027c4401c0ffa8c84bd9 100644 (file)
@@ -111,7 +111,8 @@ module CustomFieldsHelper
     content_tag(
       "label", content +
       (required ? " <span class=\"required\">*</span>".html_safe : ""),
-      :for => for_tag_id)
+      :for => for_tag_id,
+      :class => custom_value.customized && custom_value.customized.errors[custom_value.custom_field.name].present? ? 'error' : nil)
   end
 
   # Return custom field tag with its label tag
index c670b30bdaee389d2687eca215732e6abd6aaaa8..d906454a69b239329e1dc9443ec26201c50ae439 100644 (file)
@@ -65,7 +65,7 @@ class CustomFieldValue
 
   def validate_value
     custom_field.validate_custom_value(self).each do |message|
-      customized.errors.add(:base, custom_field.name + ' ' + message)
+      customized.errors.add(custom_field.name, message)
     end
   end
 end
index 2c64373112fc0fe393a4b798d46167389399c28f..1c0554f98c8072d8877514f02dafef91b3df56f6 100644 (file)
@@ -805,7 +805,7 @@ class Issue < ActiveRecord::Base
         attribute = attribute.to_i
         v = custom_field_values.detect {|v| v.custom_field_id == attribute}
         if v && Array(v.value).detect(&:present?).nil?
-          errors.add :base, v.custom_field.name + ' ' + l('activerecord.errors.messages.blank')
+          errors.add(v.custom_field.name, l('activerecord.errors.messages.blank'))
         end
       else
         if respond_to?(attribute) && send(attribute).blank? && !disabled_core_fields.include?(attribute)
index cb04adad6d1186a967b27c16939d0b1c8bf043df..83b5a911fe6410ce74a89ada176ed30fe3bd78f7 100644 (file)
@@ -4061,6 +4061,8 @@ class IssuesControllerTest < Redmine::ControllerTest
       )
     end
     assert_response :success
+
+    assert_select 'label[for=?][class=?]', "issue_custom_field_values_#{field.id}", 'error'
     assert_select_error /Database cannot be blank/
   end
 
@@ -4094,6 +4096,10 @@ class IssuesControllerTest < Redmine::ControllerTest
       )
       assert_response :success
     end
+
+    assert_select 'label[for=?][class=?]', 'issue_due_date', 'error'
+    assert_select 'label[for=?][class=?]', "issue_custom_field_values_#{cf2.id}", 'error'
+
     assert_select_error /Due date cannot be blank/i
     assert_select_error /Bar cannot be blank/i
   end