Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate value to hint element in FieldsetCheckBox #211

Merged
merged 3 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions guide/content/building-blocks/localisation.slim
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ p.govuk-body
code: department_check_boxes,
sample_data: departments_value_data_raw)

== render('/partials/example-fig.*',
caption: "A more comprehensive example of localised check boxes",
localisation: movie_genre_check_boxes_locale,
code: movie_genre_check_boxes) do
== render('/partials/fieldset-warning.*', input_type: 'check box')

== render('/partials/example-fig.*',
caption: "Customising locale structure",
localisation: custom_locale,
Expand Down
36 changes: 36 additions & 0 deletions guide/lib/examples/localisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,42 @@ def department_check_boxes_locale
LOCALE
end

def movie_genre_check_boxes
<<~SNIPPET
= f.govuk_check_boxes_fieldset :movie_genres do
= f.govuk_check_box :movie_genres, :action, link_errors: true
= f.govuk_check_box :movie_genres, :comedy
= f.govuk_check_box :movie_genres, :horror
= f.govuk_check_box :movie_genres, :other do
= f.govuk_text_field :other_movie_genres
SNIPPET
end

def movie_genre_check_boxes_locale
<<~LOCALE
helpers:
legend:
person:
movie_genres: Which movie genres do you prefer?
hint:
person:
other_movie_genres: You can enter as many as you like
movie_genres: Select all that apply
movie_genres_options:
action: War, espionage, martial arts
comedy: Parody, dark comedy
horror: Zombies, slasher, found footage
label:
person:
other_movie_genres: Which additional movie genres do you like?
movie_genres_options:
action: Action
comedy: Comedy
horror: Horror
other: Other
LOCALE
end

def role_name
<<~SNIPPET
= f.govuk_text_field :role, label: { size: 'm' }
Expand Down
2 changes: 2 additions & 0 deletions guide/lib/helpers/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Person
:department_ids,
:languages,
:other_language,
:movie_genres,
:other_movie_genres,
:terms_and_conditions_agreed
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def hint_element
end

def hint_options
{ checkbox: true }
{ value: @value, checkbox: true }
end

def conditional_classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
it_behaves_like 'a field that contains a customisable form group'

it_behaves_like 'a field that supports setting the hint via localisation'
it_behaves_like 'a field that supports localised fieldset hints' do
let(:localisation_key) { :projects_options }
let(:field_name_selector) { "projects" }
end
it_behaves_like 'a field that supports setting the legend via localisation'

it_behaves_like 'a field that accepts a plain ruby object' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
it_behaves_like 'a field that contains a customisable form group'

it_behaves_like 'a field that supports setting the hint via localisation'
it_behaves_like 'a field that supports localised fieldset hints' do
let(:localisation_key) { :favourite_colour_options }
let(:field_name_selector) { "favourite-colour" }
end
it_behaves_like 'a field that supports setting the legend via localisation'

it_behaves_like 'a field that accepts a plain ruby object' do
Expand Down
9 changes: 9 additions & 0 deletions spec/support/locales/collection_hints.en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
helpers:
hint:
person:
projects_options:
11: Xanthous
22: Yellow
favourite_colour_options:
red: Maroon
green: Pea
14 changes: 14 additions & 0 deletions spec/support/shared/shared_localisation_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,17 @@
end
end
end

shared_examples 'a field that supports localised fieldset hints' do
let(:localisations) { { en: YAML.load_file('spec/support/locales/collection_hints.en.yaml').deep_symbolize_keys } }
let(:expected_hints) { localisations.dig(:en, :helpers, :hint, :person, localisation_key) }

specify 'the hints should be set by localisation' do
with_localisations(localisations) do
expected_hints.each do |id, hint|
expected_id = ["person", field_name_selector, id, "hint"].join("-")
expect(subject).to have_tag("span", with: { id: expected_id }, text: hint)
end
end
end
end