Skip to content

Commit

Permalink
Use a hidden input for hidden facets
Browse files Browse the repository at this point in the history
This replaces the use of an input[type=text] for a hidden field. The
motivation for replacing this is that these depend on inline styles and
these will no longer be permitted by the Content Security Policy in
alphagov/govuk_app_config#279

This also serves as a semantic improvement to the HTML.
  • Loading branch information
kevindew committed Jan 16, 2023
1 parent 652773c commit 6d40d44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/modules/remove-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
if (inputType === 'checkbox') {
$input.checked = false
window.GOVUK.triggerEvent($input, 'change', { detail: { suppressAnalytics: true } })
} else if (inputType === 'text' || inputType === 'search') {
} else if (inputType === 'text' || inputType === 'search' || inputType === 'hidden') {
/* By padding the haystack with spaces, we can remove the
* first instance of " $needle ", and this will catch it in
* the middle of the haystack, at the ends, and when the
Expand Down
18 changes: 9 additions & 9 deletions app/views/finders/_hidden_clearable_facet.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div id="<%= hidden_clearable_facet.key %>" style="display: none">
<%
key = hidden_clearable_facet.key
values = params[key]
key = "#{key}[]" if values.is_a?(Array)
-%>
<% [values].flatten.each_with_index do |value, index| -%>
<div id="<%= hidden_clearable_facet.key %>">
<%
key = hidden_clearable_facet.key
values = params[key]
key = "#{key}[]" if values.is_a?(Array)
-%>
<% [values].flatten.each_with_index do |value, index| -%>


<%= text_field_tag key, value, id: "#{hidden_clearable_facet.key}_#{index}" %>
<% end -%>
<%= hidden_field_tag key, value, id: "#{hidden_clearable_facet.key}_#{index}" %>
<% end -%>
</div>

0 comments on commit 6d40d44

Please sign in to comment.