Skip to content
Open
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
2 changes: 1 addition & 1 deletion app/helpers/event_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def resolve_answer_text(field, submitted_answer)
case field&.field_identifier
when *FormField::SECTOR_FIELD_IDENTIFIERS
resolve.call(Sector)
when "primary_age_group", "additional_age_group"
when *FormField::AGE_GROUP_FIELD_IDENTIFIERS
resolve.call(Category)
else
submitted_answer
Expand Down
9 changes: 7 additions & 2 deletions app/models/form_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ class FormField < ApplicationRecord
# (as a string). Maps the field identifier to its backing CategoryType name.
DYNAMIC_FIELD_CATEGORY_TYPES = {
"primary_age_group" => "AgeRange",
"additional_age_groups" => "AgeRange",
"additional_age_group" => "AgeRange"
}.freeze

# The "primary" and "additional" age group fields. Both are backed by AgeRange
# categories but omit the catch-all "Mixed-age groups" category β€” a respondent
# names the concrete age groups they serve, not the mixed bucket.
#
# The "additional" field is multi-select, so its current identifier is plural;
# the legacy singular name is kept so existing form data keeps resolving
# (current name first, legacy last β€” matching the sector identifiers).
PRIMARY_AGE_GROUP_FIELD_IDENTIFIER = "primary_age_group"
ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIER = "additional_age_group"
AGE_GROUP_FIELD_IDENTIFIERS = [ PRIMARY_AGE_GROUP_FIELD_IDENTIFIER, ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIER ].freeze
ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIERS = %w[additional_age_groups additional_age_group].freeze
AGE_GROUP_FIELD_IDENTIFIERS = [ PRIMARY_AGE_GROUP_FIELD_IDENTIFIER, *ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIERS ].freeze

# The payment-method field. Its answer options ("Credit card (now)", etc.) are

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ€– From Claude: Current name first, legacy singular last β€” same ordering convention as ADDITIONAL_SECTOR_FIELD_IDENTIFIERS. Both keys are also added to DYNAMIC_FIELD_CATEGORY_TYPES so every .key?/[id] lookup resolves either name.

# wired to Stripe charge logic in the controllers, so they must not be edited
Expand Down
5 changes: 3 additions & 2 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ def remote_search_label
end

# Field identifiers whose "Other" free text maps onto the category-backed
# profile fields shown on the edit page.
OTHER_WORKSHOP_SETTING_IDENTIFIERS = %w[primary_age_group additional_age_group].freeze
# profile fields shown on the edit page. Mirrors the age group fields (current
# plural + legacy singular) so both keep resolving.
OTHER_WORKSHOP_SETTING_IDENTIFIERS = FormField::AGE_GROUP_FIELD_IDENTIFIERS

# Free-text "Other" sectors the person typed on registration forms.
# They can't be Sector records, so they're surfaced beside the sector tags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def assign_tags(person, organization)
primary_sector_ids = collect_sector_ids(FormField::PRIMARY_SECTOR_FIELD_IDENTIFIERS)
additional_sector_ids = collect_sector_ids(FormField::ADDITIONAL_SECTOR_FIELD_IDENTIFIERS)
primary_age_ids = collect_ids_from_checkboxes("primary_age_group")
additional_age_ids = collect_ids_from_checkboxes("additional_age_group")
additional_age_ids = FormField::ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIERS.flat_map { |id| collect_ids_from_checkboxes(id) }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ€– From Claude: Collects across both identifiers (flat_map) exactly like the sector line above, so registrations submitted against legacy singular fields still tag correctly.


if primary_sector_ids.any? || additional_sector_ids.any?
person.tag_sectors(primary_ids: primary_sector_ids, additional_ids: additional_sector_ids)
Expand Down
10 changes: 5 additions & 5 deletions app/services/form_builder_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def call
agency_street agency_city agency_state agency_zip agency_country
],
person_background: %w[racial_ethnic_identity],
professional_info: %w[primary_sector_single additional_sectors primary_age_group additional_age_group],
professional_info: %w[primary_sector_single additional_sectors primary_age_group additional_age_groups],
marketing: %w[referral_source training_motivation interested_in_more],
scholarship: %w[scholarship_eligibility scholarship_contribution impact_description implementation_plan additional_comments],
payment: %w[payment_method],
Expand Down Expand Up @@ -86,7 +86,7 @@ def call
"Organization Country"
],
person_background: [ "How would you best describe yourself?" ],
professional_info: [ "Primary sector", "Additional sectors", "Primary Age Group(s) Served", "Additional Age Group(s) Served" ],
professional_info: [ "Primary sector", "Additional sectors", "Primary age group served", "Additional age groups served" ],
marketing: [
"How did you hear about this AWBW training?",
"What motivated you to sign up for AWBW's Facilitator Training?",
Expand Down Expand Up @@ -450,11 +450,11 @@ def build_professional_info_fields(form, position)
position = add_field(form, position, "Additional sectors", :multi_select_checkbox,
key: "additional_sectors", group: "professional", required: false,
subtitle: "Select all options that represent who you intend to serve through the art workshops (check all that apply)")
position = add_field(form, position, "Primary Age Group(s) Served", :single_select_dropdown,
position = add_field(form, position, "Primary age group served", :single_select_dropdown,
key: "primary_age_group", group: "professional", required: false,
subtitle: "Select the age group you primarily intend to serve through the art workshops")
position = add_field(form, position, "Additional Age Group(s) Served", :multi_select_checkbox,
key: "additional_age_group", group: "professional", required: false,
position = add_field(form, position, "Additional age groups served", :multi_select_checkbox,
key: "additional_age_groups", group: "professional", required: false,
subtitle: "Select all additional age groups you may serve through the art workshops (check all that apply)")
position
end
Expand Down
10 changes: 9 additions & 1 deletion spec/models/form_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,20 @@ def selectable_field(type:, option_names:)
type = create(:category_type, name: "AgeRange")
concrete = create(:category, :published, category_type: type, name: "3-5")
mixed = create(:category, :published, category_type: type, name: Category::MIXED_AGE_RANGE_NAME)
field = create(:form_field, form: form, answer_type: :multi_select_checkbox, field_identifier: "additional_age_group")
field = create(:form_field, form: form, answer_type: :multi_select_checkbox, field_identifier: "additional_age_groups")

expect(field.dynamic_categories).to eq([ concrete ])
expect(field.answer_inclusion_error([ concrete.id.to_s ])).to be_nil
expect(field.answer_inclusion_error([ mixed.id.to_s ])).to eq("has an invalid selection")
end

it "still resolves the legacy singular additional_age_group identifier" do
type = create(:category_type, name: "AgeRange")
concrete = create(:category, :published, category_type: type, name: "3-5")
field = create(:form_field, form: form, answer_type: :multi_select_checkbox, field_identifier: "additional_age_group")

expect(field.dynamic_categories).to eq([ concrete ])
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def register_with(position:)
form: form,
form_params: base_form_params(first_name: "Al", last_name: "Ng", email: "al@example.com").merge(
field_id("primary_age_group") => [ young.id.to_s ],
field_id("additional_age_group") => [ teen.id.to_s ]
field_id("additional_age_groups") => [ teen.id.to_s ]
)
)

Expand Down
2 changes: 1 addition & 1 deletion spec/services/form_builder_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@

it "asks for a single primary age group via a dropdown alongside additional-age checkboxes" do
primary = form.form_fields.find_by(field_identifier: "primary_age_group")
additional = form.form_fields.find_by(field_identifier: "additional_age_group")
additional = form.form_fields.find_by(field_identifier: "additional_age_groups")

expect(primary.answer_type).to eq("single_select_dropdown")
expect(additional.answer_type).to eq("multi_select_checkbox")
Expand Down
4 changes: 2 additions & 2 deletions spec/system/public_registration_form_submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"primary_sector_single" => sector_education.id.to_s,
"additional_sectors" => sector_mental_health.id.to_s,
"primary_age_group" => age_adults.id.to_s,
"additional_age_group" => age_teens.id.to_s,
"additional_age_groups" => age_teens.id.to_s,
"racial_ethnic_identity" => "Multi-racial",
"referral_source" => "Online Search",
"training_motivation" => "Address staff burnout through art",
Expand Down Expand Up @@ -393,7 +393,7 @@ def fill_full_registration
select_pr reg_field("primary_sector_single"), "Education"
check_pr_box reg_field("additional_sectors"), sector_mental_health.id.to_s
select_pr reg_field("primary_age_group"), "Adults (18+)"
check_pr_box reg_field("additional_age_group"), age_teens.id.to_s
check_pr_box reg_field("additional_age_groups"), age_teens.id.to_s

choose_pr_radio reg_field("racial_ethnic_identity"), "Multi-racial"
choose_pr_radio reg_field("referral_source"), "Online Search"
Expand Down