From 1dfbcb00311de4b142290867b4b8a0a2e4cf6b6f Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 26 Feb 2025 11:06:15 +0100 Subject: [PATCH] Add stars to forms --- .../components/inputs/SirenInput.jsx | 23 ++++++++++++++++++- .../entreprises/_form_fields.html.slim | 10 ++++---- .../_form_fields.html.slim | 1 + .../stepper/plannings/_form_fields.html.slim | 1 + 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/front_assets/components/inputs/SirenInput.jsx b/app/front_assets/components/inputs/SirenInput.jsx index c96a4ddcf..017fed3ea 100644 --- a/app/front_assets/components/inputs/SirenInput.jsx +++ b/app/front_assets/components/inputs/SirenInput.jsx @@ -142,6 +142,9 @@ export default function SirenInput({ const ministry = document.getElementById("ministry-choice"); const ministryClassList = ministry.classList; + const sectorBloc = document.getElementById("sector-choice-block"); + const sectorBlocClassList = sectorBloc.classList; + const sector = document.getElementById("sector-choice"); // TODO pub/sub with broadcasting would be better // because both jsx and stimulus send events to the containers (show/hide) ministryClassList.add("d-none"); // default @@ -151,9 +154,27 @@ export default function SirenInput({ const hiddenField = document.getElementById("hidden-public-private-field") .children[0]; hiddenField.value = is_public; toggleContainer(hiddenField, true); + if (is_public) { ministry.removeAttribute("style"); ministryClassList.remove("d-none"); + + // For public establishments + + sectorBlocClassList.add("d-none"); + // Safely check and select "Fonction publique" option + if (sector && sector.options) { + for (let i = 0; i < sector.options.length; i++) { + if (sector.options[i].text.toLowerCase().includes('fonction publique')) { + sector.value = sector.options[i].value; + break; + } + } + } + } else { + // For private companies + sectorBlocClassList.remove("d-none"); + sector.value = ""; } } }; @@ -224,7 +245,7 @@ export default function SirenInput({ htmlFor: `${resourceName}_siren`, })} > - Indiquez le nom ou le SIRET de la structure d’accueil * + Indiquez le nom ou le SIRET de la structure d'accueil * {railsEnv === "development" ? " (dev only : 21950572400209)" : ""} diff --git a/app/views/dashboard/stepper/entreprises/_form_fields.html.slim b/app/views/dashboard/stepper/entreprises/_form_fields.html.slim index 266e44f44..b9a2399d0 100644 --- a/app/views/dashboard/stepper/entreprises/_form_fields.html.slim +++ b/app/views/dashboard/stepper/entreprises/_form_fields.html.slim @@ -5,6 +5,7 @@ data-ministry-fields-new-record-value="#{resource.new_record?}" data-ministry-fields-is-entreprise-public-value="#{resource.try(:is_public) ? 'true' : 'false'}" ] .row + .col-12= form.rg2a_explain_required_asterisk(p_class_name: "mb-0") .col-md-6.order-md-2.order-1.d-none.d-md-block - if form.object.new_record? && show_resume = render 'dashboard/stepper/summary_card', form: form @@ -72,23 +73,24 @@ #ministry-choice.row.fr-mt-3w.bloc-tooggle.d-none [data-ministry-fields-target="groupNamePublic"] .col-12 = form.label :group_id, class: 'fr-label' do - = "Type d’employeur public" + = "Type d’employeur public *" = form.select :group_id, options_for_select(options_for_public_groups, resource.group.try(:id)), - { prompt: '-- Choisissez votre ministère de tutelle --' }, + { }, class: "fr-select ", required: false, :'data-ministry-fields-target' => 'selectGroupName' - div class="row fr-mt-3w bloc-tooggle #{form.object.persisted? ? '' : 'd-none'}" + div#sector-choice-block class="row fr-mt-3w bloc-tooggle #{form.object.persisted? ? '' : 'd-none'}" .col-12 = form.label :sector_id , class: 'fr-label'do - = "Indiquez le secteur d'activité de votre structure" + = "Indiquez le secteur d'activité de votre structure *" = form.select :sector_id, options_from_collection_for_select(Sector.all.order(:name), :id, :name, resource.sector_id), { prompt: sectors_options_for_default }, class: "fr-select", required: true, + id: "sector-choice", data: { :'fill-card-target' => "sectorInput", :'mandatory-fields-target' => "mandatoryField", data: { action: "input->mandatory-fields#fieldChange change->fill-card#sectorChanged"}} diff --git a/app/views/dashboard/stepper/internship_occupations/_form_fields.html.slim b/app/views/dashboard/stepper/internship_occupations/_form_fields.html.slim index 0e364d7f1..d18c957e8 100644 --- a/app/views/dashboard/stepper/internship_occupations/_form_fields.html.slim +++ b/app/views/dashboard/stepper/internship_occupations/_form_fields.html.slim @@ -7,6 +7,7 @@ data-mandatory-fields-with-coordinates-minimum-length-value="6" data-mandatory-fields-with-coordinates-maximum-length-value="#{InternshipOffer::EMPLOYER_DESCRIPTION_MAX_CHAR_COUNT}" data-mandatory-fields-with-coordinates-no-event-check-value="#{resource.id.present?}"] + .col-12= form.rg2a_explain_required_asterisk(p_class_name: "mb-0") .col-md-6 .row.bloc-tooggle class=('d-old-none' if request.fullpath.include?('internship_occupations/nouveau')) .col-12 diff --git a/app/views/dashboard/stepper/plannings/_form_fields.html.slim b/app/views/dashboard/stepper/plannings/_form_fields.html.slim index 80a2289bb..2f97a9988 100644 --- a/app/views/dashboard/stepper/plannings/_form_fields.html.slim +++ b/app/views/dashboard/stepper/plannings/_form_fields.html.slim @@ -4,6 +4,7 @@ data-grade-initial-grades-value="#{resource.grades.compact&.map(&:short_name).join(',')}"] = form.hidden_field :type, value: resource.type, data: { :"planning-candidates-target" => "type" } unless resource.is_a?(Planning) .row + .col-12= form.rg2a_explain_required_asterisk(p_class_name: "mb-0") .col-md-6.order-md-2.order-1.d-none.d-md-block - if form.object.new_record? && !duplication = render 'dashboard/stepper/summary_card', form: form