activeadmin_addons icon indicating copy to clipboard operation
activeadmin_addons copied to clipboard

[BUG] Selected List throwing ActionView::Template::Error with ActionView 7.2

Open tobischo opened this issue 1 year ago • 0 comments

Describe the bug

After upgrading Rails/ActionView to v7.2 an exception started to be raised, during test execution as well as in the UI:

     Failure/Error: raise ArgumentError, "Invalid HTML5 tag name: #{name.inspect}" unless /\A[a-zA-Z][^\s\/>]*\z/.match?(name)

     ActionView::Template::Error:
       Invalid HTML5 tag name: "<label for=\"scope_field_name\" class=\"label\">Entity</label>"

To Reproduce Steps to reproduce the behavior:

  1. Create a project with Rails 7.2
  2. Add ActiveAdmin + ActiveAdmin Addons
  3. Setup a field with selected_list
  4. Open page showing the form element
  5. See Error
        f.inputs do
          f.input :field_name,
                  as:           :selected_list,
                  display_name: :display_name,
                  fields:       [:display_name],
                  predicate:    'cont',
                  url:          '/admin/entity',
                  label:        'Entity'
        end

Expected behavior It renders the select field as it did before on Rails 7.1.3.4

Screenshots

  • none -

Additional context

  • Rails 7.2 introduced this check method ensure_valid_html5_tag_name
    • https://github.com/rails/rails/blob/d7f93473682d9b64ab268a6736d5af2853e97ce2/actionview/lib/action_view/helpers/tag_helper.rb#L591
  • ActiveAdmin Addons is calling content_tag with html instead of the tag name
    • https://github.com/rails/rails/blob/d7f93473682d9b64ab268a6736d5af2853e97ce2/actionview/lib/action_view/helpers/tag_helper.rb#L532
    • e.g. <label for="scope_field_name" class="label">Entity</label> as the label_html value
      • https://github.com/platanus/activeadmin_addons/blob/cf71013d7423d4ba7a5f721acf35731fbcd37f37/app/inputs/selected_list_input.rb#L29
  • Monkey patching it to the following appears to solve it for now:
class SelectedListInput < ActiveAdminAddons::InputBase
  def render_control_wrapper
    template.content_tag(:div, class: "selected-list-container") do
      template.content_tag(:label) #patch to ensure no html is passed
      template.concat(render_items_list)
      template.concat(builder.select(build_virtual_attr, [], {}, input_html_options))
    end
  end
end
  • The same would apply for the other input types

tobischo avatar Aug 12 '24 12:08 tobischo