diff --git a/src/api/app/views/webui/projects/label_templates/_form.html.haml b/src/api/app/views/webui/projects/label_templates/_form.html.haml index 263b9c691d68..0e71e08e1201 100644 --- a/src/api/app/views/webui/projects/label_templates/_form.html.haml +++ b/src/api/app/views/webui/projects/label_templates/_form.html.haml @@ -4,9 +4,9 @@ = form.label(:name, 'Name:', class: 'form-label') = form.text_field(:name, class: classes_with_validation(label_template, :name)) - label_template.errors.where(:name).each do |error| - .error-message= error.message.capitalize + .invalid-feedback= error.message.capitalize .mb-3#color = form.label(:color, 'Color:', class: 'form-label') = form.color_field(:color, class: classes_with_validation(label_template, :color)) - label_template.errors.where(:color).each do |error| - .error-message= error.message.capitalize + .invalid-feedback= error.message.capitalize diff --git a/src/api/config/initializers/field_with_errors.rb b/src/api/config/initializers/field_with_errors.rb new file mode 100644 index 000000000000..129505d38d2b --- /dev/null +++ b/src/api/config/initializers/field_with_errors.rb @@ -0,0 +1,8 @@ +# Rails form helpers wrap controls with a .field_with_errors class that prevents the validation styles from bootstrap to work. +# This snippet replaces the wrapping with that class with an injection of .is-invalid class, which is bootstrap compatible. +ActionView::Base.field_error_proc = proc do |html| + frag = Nokogiri::HTML5::DocumentFragment.parse(html) + klass = frag.children[0].attributes['class'] + frag.children[0].attributes['class'].value = [klass, 'is-invalid'].join(' ') + frag.to_html.html_safe # rubocop:disable Rails/OutputSafety The input is code from our views, so it's safe to disable this +end