From 477c1e8bca82aafb05d7e1a296eb5aa990d97b04 Mon Sep 17 00:00:00 2001 From: Lori Bailey <44073106+elceebee@users.noreply.github.com> Date: Thu, 16 May 2024 17:15:59 +0100 Subject: [PATCH] Replace study mode radio buttons with check boxes when editing a course --- .../publish/courses/study_mode_controller.rb | 2 +- app/forms/publish/course_study_mode_form.rb | 2 +- .../publish/courses/study_mode/edit.html.erb | 20 +++++--- app/views/publish/shared/_errors.html.erb | 2 + .../courses/editing_course_study_mode_spec.rb | 49 +++++++++++++++++-- .../publish/courses/new_funding_type_spec.rb | 2 +- spec/features/publish/e2e/new_course_spec.rb | 2 +- .../publish/course_study_mode_form_spec.rb | 28 +++++++++-- .../services/courses/creation_service_spec.rb | 22 ++++++--- .../new_course_param_helper.rb | 10 ++-- .../publish/course_study_mode_edit.rb | 5 +- .../publish/courses/new_study_mode.rb | 4 +- 12 files changed, 110 insertions(+), 38 deletions(-) diff --git a/app/controllers/publish/courses/study_mode_controller.rb b/app/controllers/publish/courses/study_mode_controller.rb index af4c203602..259d8855d8 100644 --- a/app/controllers/publish/courses/study_mode_controller.rb +++ b/app/controllers/publish/courses/study_mode_controller.rb @@ -33,7 +33,7 @@ def update def study_mode_params return { study_mode: nil } if params[:publish_course_study_mode_form].blank? - params.require(:publish_course_study_mode_form).permit(*CourseStudyModeForm::FIELDS) + params.require(:publish_course_study_mode_form).permit(study_mode: []) end def current_step diff --git a/app/forms/publish/course_study_mode_form.rb b/app/forms/publish/course_study_mode_form.rb index 6b056434cd..f7ea897544 100644 --- a/app/forms/publish/course_study_mode_form.rb +++ b/app/forms/publish/course_study_mode_form.rb @@ -19,7 +19,7 @@ def valid_before_save end def compute_fields - course.attributes.symbolize_keys.slice(*FIELDS).merge(new_attributes) + { study_mode: new_attributes[:study_mode]&.compact_blank&.sort&.join('_or_') } end end end diff --git a/app/views/publish/courses/study_mode/edit.html.erb b/app/views/publish/courses/study_mode/edit.html.erb index f9994a7707..1f2079e621 100644 --- a/app/views/publish/courses/study_mode/edit.html.erb +++ b/app/views/publish/courses/study_mode/edit.html.erb @@ -26,14 +26,18 @@ <%= f.govuk_error_summary %> - <%= f.govuk_radio_buttons_fieldset(:study_mode, legend: { text: "#{render CaptionText.new(text: course.name_and_code)} Full time or part time?".html_safe, tag: "h1", size: "l" }) do %> - <% course.edit_course_options["study_modes"].each_with_index do |study_mode, index| %> - <%= f.govuk_radio_button( - :study_mode, - study_mode, - label: { text: t("edit_options.study_modes.#{study_mode}.label") }, - link_errors: index.zero? - ) %> + <%= f.govuk_check_boxes_fieldset :study_mode, + hint: { text: t("publish.providers.study_mode.form.select_all_that_apply") }, + legend: { text: "#{render CaptionText.new(text: course.name_and_code)} #{t('publish.providers.study_mode.form.study_pattern')}".html_safe, + tag: "h1", + size: "l" } do %> + <% course.edit_course_options[:study_modes].each_with_index do |value, index| %> + <%= f.govuk_check_box :study_mode, + value, + label: { text: t("edit_options.study_modes.#{value}.label") }, + checked: course.study_mode.in?([value, "full_time_or_part_time"]), + link_errors: index.zero? %> + <% end %> <% end %> diff --git a/app/views/publish/shared/_errors.html.erb b/app/views/publish/shared/_errors.html.erb index b4bdaedda4..9e5f8a1984 100644 --- a/app/views/publish/shared/_errors.html.erb +++ b/app/views/publish/shared/_errors.html.erb @@ -1,3 +1,5 @@ +<%# locals: (error_id: nil) -%> + <% if @errors && @errors.any? %>