Commit 6a35c52c authored by Marius Balteanu's avatar Marius Balteanu
Browse files

Add class 'error' to custom fields with validation errors

parent 4efaff7e
Pipeline #239464521 failed with stage
in 13 minutes and 32 seconds
......@@ -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
......
......@@ -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
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment