0001-Add-class-error-to-custom-fields-with-validation-err.patch

Marius BALTEANU, 2021-01-09 20:36

Download (3.1 KB)

View differences:

app/helpers/custom_fields_helper.rb
111 111
    content_tag(
112 112
      "label", content +
113 113
      (required ? " <span class=\"required\">*</span>".html_safe : ""),
114
      :for => for_tag_id)
114
      :for => for_tag_id,
115
      :class => custom_value.customized && custom_value.customized.errors[custom_value.custom_field.name].present? ? 'error' : nil)
115 116
  end
116 117

  
117 118
  # Return custom field tag with its label tag
app/models/custom_field_value.rb
65 65

  
66 66
  def validate_value
67 67
    custom_field.validate_custom_value(self).each do |message|
68
      customized.errors.add(:base, custom_field.name + ' ' + message)
68
      customized.errors.add(custom_field.name, message)
69 69
    end
70 70
  end
71 71
end
app/models/issue.rb
805 805
        attribute = attribute.to_i
806 806
        v = custom_field_values.detect {|v| v.custom_field_id == attribute}
807 807
        if v && Array(v.value).detect(&:present?).nil?
808
          errors.add :base, v.custom_field.name + ' ' + l('activerecord.errors.messages.blank')
808
          errors.add(v.custom_field.name, l('activerecord.errors.messages.blank'))
809 809
        end
810 810
      else
811 811
        if respond_to?(attribute) && send(attribute).blank? && !disabled_core_fields.include?(attribute)
test/functional/issues_controller_test.rb
4061 4061
      )
4062 4062
    end
4063 4063
    assert_response :success
4064

  
4065
    assert_select 'label[for=?][class=?]', "issue_custom_field_values_#{field.id}", 'error'
4064 4066
    assert_select_error /Database cannot be blank/
4065 4067
  end
4066 4068

  
......
4094 4096
      )
4095 4097
      assert_response :success
4096 4098
    end
4099

  
4100
    assert_select 'label[for=?][class=?]', 'issue_due_date', 'error'
4101
    assert_select 'label[for=?][class=?]', "issue_custom_field_values_#{cf2.id}", 'error'
4102

  
4097 4103
    assert_select_error /Due date cannot be blank/i
4098 4104
    assert_select_error /Bar cannot be blank/i
4099 4105
  end
4100
-