activeadmin_addons
activeadmin_addons copied to clipboard
[BUG] Selected List throwing ActionView::Template::Error with ActionView 7.2
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:
- Create a project with Rails 7.2
- Add ActiveAdmin + ActiveAdmin Addons
- Setup a field with
selected_list - Open page showing the form element
- 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 thelabel_htmlvalue- 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