Skip to content

Commit b10ee20

Browse files
Fix autocomplete JavaScript call (#86)
Fixes a regression in the JavaScript call for autocomplete elements that transformed the surrounding quotes to HTML entities therefore causing errors.
1 parent 6dd5761 commit b10ee20

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
govuk-design-system-rails (0.10.2)
4+
govuk-design-system-rails (0.10.3)
55

66
GEM
77
remote: https://rubygems.org/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You **must** include the [govuk-frontend](https://github.com/alphagov/govuk-fron
1414

1515
| This gem's version | Compatible with `govuk-frontend` version |
1616
|--------------------| --- |
17-
| 0.10.2 | 4.3.1 |
17+
| 0.9.7 | 4.3.1 |
1818
| 0.9.0 | 4.1.0 |
1919
| 0.8.2 | 3.14.0 |
2020

app/views/components/_govuk_select.html.erb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@
9696
</svg>
9797
</button>
9898
<% end %>
99+
99100
<script nonce="true">
100-
//<![CDATA[
101-
window.callAutocompleteWhenReady(<%= local_assigns[:id].to_json %>, { showAllValues: <%= local_assigns[:show_all_values].to_json %> });
102-
//]]>
101+
// <![CDATA[
102+
window.callAutocompleteWhenReady(<%= local_assigns[:id].to_json.html_safe %>, { showAllValues: <%= local_assigns[:show_all_values].to_json.html_safe %> });
103+
// ]]>
103104
</script>
104105
<% else %>
105106
<%= select %>

govuk-design-system-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ $LOAD_PATH.push File.expand_path("lib", __dir__)
22

33
Gem::Specification.new do |s|
44
s.name = "govuk-design-system-rails"
5-
s.version = "0.10.2"
5+
s.version = "0.10.3"
66
s.authors = %w[govuk-ruby]
77
s.summary = "An implementation of the govuk-frontend macros in Ruby on Rails"
88
s.homepage = "https://github.com/govuk-ruby/govuk-design-system-rails"

spec/helpers/govuk_design_system/select_helper_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,56 @@
8181
</div>
8282
HTML
8383
end
84+
85+
it "returns the correct HTML when the select element is an autocomplete element" do
86+
html = helper.govukSelect({
87+
id: "sort",
88+
name: "sort",
89+
label: {
90+
text: "Sort by"
91+
},
92+
items: [
93+
{
94+
value: "published",
95+
text: "Recently published"
96+
},
97+
{
98+
value: "updated",
99+
text: "Recently updated",
100+
selected: true
101+
},
102+
{
103+
value: "views",
104+
text: "Most views"
105+
},
106+
{
107+
value: "comments",
108+
text: "Most comments"
109+
}
110+
],
111+
is_autocomplete: true
112+
})
113+
114+
expect(html).to match_html(<<~HTML)
115+
<div class="govuk-form-group">
116+
<label class="govuk-label" for="sort">
117+
Sort by
118+
</label>
119+
<div class="">
120+
<select class="govuk-select" id="sort" name="sort">
121+
<option value="published">Recently published</option>
122+
<option value="updated" selected="selected">Recently updated</option>
123+
<option value="views">Most views</option>
124+
<option value="comments">Most comments</option>
125+
</select>
126+
</div>
127+
<script nonce="true">
128+
// <![CDATA[
129+
window.callAutocompleteWhenReady("sort", { showAllValues: null });
130+
// ]]>
131+
</script>
132+
</div>
133+
HTML
134+
end
84135
end
85136
end

0 commit comments

Comments
 (0)