diff --git a/app/views/shared/attachment/_edit.html.haml b/app/views/shared/attachment/_edit.html.haml index 54ec64236..d61f555b9 100644 --- a/app/views/shared/attachment/_edit.html.haml +++ b/app/views/shared/attachment/_edit.html.haml @@ -6,6 +6,7 @@ - accept = defined?(accept) ? accept : nil - user_can_destroy = defined?(user_can_destroy) ? user_can_destroy : false - direct_upload = direct_upload != nil ? false : true +- champ = form.object.is_a?(Champ) ? form.object : nil .attachment - if defined?(template) && template.attached? @@ -36,4 +37,6 @@ class: "attachment-input attachment-input-#{attachment_id} #{'hidden' if persisted}", accept: accept, direct_upload: direct_upload, + id: champ&.input_id, + aria: { describedby: champ&.describedby_id }, data: { 'auto-attach-url': auto_attach_url(form, form.object) } diff --git a/app/views/shared/dossiers/editable_champs/_address.html.haml b/app/views/shared/dossiers/editable_champs/_address.html.haml index 4d3be0a26..10cb637b3 100644 --- a/app/views/shared/dossiers/editable_champs/_address.html.haml +++ b/app/views/shared/dossiers/editable_champs/_address.html.haml @@ -1,4 +1,6 @@ -- hidden_field_id = SecureRandom.uuid -= form.hidden_field :value, { data: { uuid: hidden_field_id } } -= form.hidden_field :external_id, { data: { reference: true } } -= react_component("ComboAdresseSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id) += form.hidden_field :value += form.hidden_field :external_id += react_component("ComboAdresseSearch", + required: champ.mandatory?, + id: champ.input_id, + describedby: champ.describedby_id) diff --git a/app/views/shared/dossiers/editable_champs/_annuaire_education.html.haml b/app/views/shared/dossiers/editable_champs/_annuaire_education.html.haml index d550752b5..4c59e2ffe 100644 --- a/app/views/shared/dossiers/editable_champs/_annuaire_education.html.haml +++ b/app/views/shared/dossiers/editable_champs/_annuaire_education.html.haml @@ -1,4 +1,6 @@ -- hidden_field_id = SecureRandom.uuid -= form.hidden_field :value, { data: { uuid: hidden_field_id } } -= form.hidden_field :external_id, { data: { reference: true } } -= react_component("ComboAnnuaireEducationSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id ) += form.hidden_field :value += form.hidden_field :external_id += react_component("ComboAnnuaireEducationSearch", + required: champ.mandatory?, + id: champ.input_id, + describedby: champ.describedby_id) diff --git a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml index fc341a5d2..6258a7bcf 100644 --- a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml +++ b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml @@ -1,10 +1,10 @@ = # we do this trick because some html elements should use 'label' and some should be plain paragraphs - if champ.html_label? - = form.label champ.main_value_name do + = form.label champ.main_value_name, id: champ.labelledby_id, for: champ.input_id do = render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at } - else .form-label.mb-4 = render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at } - if champ.description.present? - .notice{ id: describedby_id(champ) }= string_to_html(champ.description) + .notice{ id: champ.describedby_id }= string_to_html(champ.description) diff --git a/app/views/shared/dossiers/editable_champs/_checkbox.html.haml b/app/views/shared/dossiers/editable_champs/_checkbox.html.haml index 707b2adcd..ca8743947 100644 --- a/app/views/shared/dossiers/editable_champs/_checkbox.html.haml +++ b/app/views/shared/dossiers/editable_champs/_checkbox.html.haml @@ -1,4 +1,4 @@ = form.check_box :value, - { required: champ.mandatory? }, + { required: champ.mandatory?, id: champ.input_id, aria: { describedby: champ.describedby_id } }, 'on', 'off' diff --git a/app/views/shared/dossiers/editable_champs/_cnaf.html.haml b/app/views/shared/dossiers/editable_champs/_cnaf.html.haml index 1d8d90610..455a7e516 100644 --- a/app/views/shared/dossiers/editable_champs/_cnaf.html.haml +++ b/app/views/shared/dossiers/editable_champs/_cnaf.html.haml @@ -5,7 +5,7 @@ = form.text_field :numero_allocataire, required: champ.mandatory?, size: 7, - aria: { describedby: describedby_id(champ) } + aria: { describedby: champ.describedby_id } %div = form.label :code_postal, t('.code_postal_label') @@ -13,4 +13,4 @@ = form.text_field :code_postal, size: 5, required: champ.mandatory?, - aria: { describedby: describedby_id(champ) } + aria: { describedby: champ.describedby_id } diff --git a/app/views/shared/dossiers/editable_champs/_communes.html.haml b/app/views/shared/dossiers/editable_champs/_communes.html.haml index 0e43f37b6..ca33da594 100644 --- a/app/views/shared/dossiers/editable_champs/_communes.html.haml +++ b/app/views/shared/dossiers/editable_champs/_communes.html.haml @@ -1,6 +1,8 @@ -- hidden_field_id = SecureRandom.uuid -= form.hidden_field :value, { data: { uuid: hidden_field_id } } -= form.hidden_field :external_id, { data: { reference: true } } -= form.hidden_field :departement, { data: { attr: "#{hidden_field_id}:departement" } } -= form.hidden_field :code_departement, { data: { attr: "#{hidden_field_id}:code_departement" } } -= react_component("ComboCommunesSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id) += form.hidden_field :value += form.hidden_field :external_id += form.hidden_field :departement += form.hidden_field :code_departement += react_component("ComboCommunesSearch", + required: champ.mandatory?, + id: champ.input_id, + describedby: champ.describedby_id) diff --git a/app/views/shared/dossiers/editable_champs/_date.html.haml b/app/views/shared/dossiers/editable_champs/_date.html.haml index 1f0c344d2..7ca761d22 100644 --- a/app/views/shared/dossiers/editable_champs/_date.html.haml +++ b/app/views/shared/dossiers/editable_champs/_date.html.haml @@ -1,4 +1,6 @@ = form.date_field :value, + id: champ.input_id, + aria: { describedby: champ.describedby_id }, value: champ.value, required: champ.mandatory?, placeholder: 'aaaa-mm-jj' diff --git a/app/views/shared/dossiers/editable_champs/_datetime.html.haml b/app/views/shared/dossiers/editable_champs/_datetime.html.haml index 3283633f9..3c1756dae 100644 --- a/app/views/shared/dossiers/editable_champs/_datetime.html.haml +++ b/app/views/shared/dossiers/editable_champs/_datetime.html.haml @@ -1,4 +1,4 @@ - parsed_value = champ.value.present? ? Time.zone.parse(champ.value) : nil .datetime - = form.datetime_select(:value, selected: parsed_value, start_year: datetime_start_year(parsed_value), end_year: Date.today.year + 50, minute_step: 5, include_blank: true) + = form.datetime_select(:value, id: champ.input_id, aria: { describedby: champ.describedby_id }, selected: parsed_value, start_year: datetime_start_year(parsed_value), end_year: Date.today.year + 50, minute_step: 5, include_blank: true) diff --git a/app/views/shared/dossiers/editable_champs/_decimal_number.html.haml b/app/views/shared/dossiers/editable_champs/_decimal_number.html.haml index 6e7aa3c8a..34a27270f 100644 --- a/app/views/shared/dossiers/editable_champs/_decimal_number.html.haml +++ b/app/views/shared/dossiers/editable_champs/_decimal_number.html.haml @@ -1,4 +1,6 @@ = form.number_field :value, + id: champ.input_id, + aria: { describedby: champ.describedby_id }, step: :any, placeholder: champ.libelle, required: champ.mandatory? diff --git a/app/views/shared/dossiers/editable_champs/_departements.html.haml b/app/views/shared/dossiers/editable_champs/_departements.html.haml index a062f3671..f91cd543b 100644 --- a/app/views/shared/dossiers/editable_champs/_departements.html.haml +++ b/app/views/shared/dossiers/editable_champs/_departements.html.haml @@ -1,4 +1,6 @@ -- hidden_field_id = SecureRandom.uuid -= form.hidden_field :value, { data: { uuid: hidden_field_id } } -= form.hidden_field :external_id, { data: { reference: true } } -= react_component("ComboDepartementsSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id) += form.hidden_field :value += form.hidden_field :external_id += react_component("ComboDepartementsSearch", + required: champ.mandatory?, + id: champ.input_id, + describedby: champ.describedby_id) diff --git a/app/views/shared/dossiers/editable_champs/_dgfip.html.haml b/app/views/shared/dossiers/editable_champs/_dgfip.html.haml index f94edf0d3..47ecd18b2 100644 --- a/app/views/shared/dossiers/editable_champs/_dgfip.html.haml +++ b/app/views/shared/dossiers/editable_champs/_dgfip.html.haml @@ -5,7 +5,7 @@ = form.text_field :numero_fiscal, required: champ.mandatory?, size: 14, - aria: { describedby: describedby_id(champ) } + aria: { describedby: champ.describedby_id } %div = form.label :reference_avis, t('.reference_avis_label') @@ -13,4 +13,4 @@ = form.text_field :reference_avis, size: 14, required: champ.mandatory?, - aria: { describedby: describedby_id(champ) } + aria: { describedby: champ.describedby_id } diff --git a/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml b/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml index 37e67954c..2ac650300 100644 --- a/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml +++ b/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml @@ -1,5 +1,7 @@ .dossier-link{ class: "dossier-link-#{form.index}" } = form.number_field :value, + id: champ.input_id, + aria: { describedby: champ.describedby_id }, placeholder: "Numéro de dossier", autocomplete: 'off', required: champ.mandatory?, diff --git a/app/views/shared/dossiers/editable_champs/_drop_down_list.html.haml b/app/views/shared/dossiers/editable_champs/_drop_down_list.html.haml index ec7f81ee7..d374cd0cb 100644 --- a/app/views/shared/dossiers/editable_champs/_drop_down_list.html.haml +++ b/app/views/shared/dossiers/editable_champs/_drop_down_list.html.haml @@ -16,7 +16,7 @@ = form.radio_button :value, Champs::DropDownListChamp::OTHER, checked: champ.other_value_present? Autre - else - = form.select :value, champ.options, selected: champ.selected, required: champ.mandatory? + = form.select :value, champ.options, { selected: champ.selected}, required: champ.mandatory?, id: champ.input_id, aria: { describedby: champ.describedby_id } - if champ.drop_down_other? = render partial: "shared/dossiers/drop_down_other_input", locals: { form: form, champ: champ } diff --git a/app/views/shared/dossiers/editable_champs/_editable_champ.html.haml b/app/views/shared/dossiers/editable_champs/_editable_champ.html.haml index bb5100ae1..c449fd4ba 100644 --- a/app/views/shared/dossiers/editable_champs/_editable_champ.html.haml +++ b/app/views/shared/dossiers/editable_champs/_editable_champ.html.haml @@ -1,4 +1,4 @@ -.editable-champ{ class: "editable-champ-#{champ.type_champ}", data: { 'champ-id': champ.id } } +.editable-champ{ class: "editable-champ-#{champ.type_champ}", id: champ.input_group_id } - if champ.repetition? %h3.header-subsection= champ.libelle - if champ.description.present? diff --git a/app/views/shared/dossiers/editable_champs/_email.html.haml b/app/views/shared/dossiers/editable_champs/_email.html.haml index ce589db77..f226889e5 100644 --- a/app/views/shared/dossiers/editable_champs/_email.html.haml +++ b/app/views/shared/dossiers/editable_champs/_email.html.haml @@ -1,3 +1,5 @@ = form.email_field :value, + id: champ.input_id, + aria: { describedby: champ.describedby_id }, placeholder: champ.libelle, required: champ.mandatory? diff --git a/app/views/shared/dossiers/editable_champs/_engagement.html.haml b/app/views/shared/dossiers/editable_champs/_engagement.html.haml index 707b2adcd..ca8743947 100644 --- a/app/views/shared/dossiers/editable_champs/_engagement.html.haml +++ b/app/views/shared/dossiers/editable_champs/_engagement.html.haml @@ -1,4 +1,4 @@ = form.check_box :value, - { required: champ.mandatory? }, + { required: champ.mandatory?, id: champ.input_id, aria: { describedby: champ.describedby_id } }, 'on', 'off' diff --git a/app/views/shared/dossiers/editable_champs/_iban.html.haml b/app/views/shared/dossiers/editable_champs/_iban.html.haml index 149b436db..04bf7d9f6 100644 --- a/app/views/shared/dossiers/editable_champs/_iban.html.haml +++ b/app/views/shared/dossiers/editable_champs/_iban.html.haml @@ -1,4 +1,5 @@ = form.text_field :value, + id: champ.input_id, placeholder: "27 caractères au format FR7630006000011234567890189", required: champ.mandatory?, - aria: { describedby: describedby_id(champ) } + aria: { describedby: champ.describedby_id } diff --git a/app/views/shared/dossiers/editable_champs/_integer_number.html.haml b/app/views/shared/dossiers/editable_champs/_integer_number.html.haml index d5aab710a..97b45497b 100644 --- a/app/views/shared/dossiers/editable_champs/_integer_number.html.haml +++ b/app/views/shared/dossiers/editable_champs/_integer_number.html.haml @@ -1,3 +1,5 @@ = form.number_field :value, + id: champ.input_id, + aria: { describedby: champ.describedby_id }, placeholder: champ.libelle, required: champ.mandatory? diff --git a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml index 0f88b773e..aa3531c10 100644 --- a/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml +++ b/app/views/shared/dossiers/editable_champs/_linked_drop_down_list.html.haml @@ -1,16 +1,16 @@ - if champ.options? = form.select :primary_value, champ.primary_options, - { required: champ.mandatory? }, - { data: { secondary_options: champ.secondary_options } } - %span - = form.label :secondary_value do - = champ.drop_down_secondary_libelle.presence || "Valeur secondaire dépendant de la première" - - if champ.mandatory? - %span.mandatory * - - if champ.drop_down_secondary_description.present? - .notice= string_to_html(champ.drop_down_secondary_description) + {}, + { data: { secondary_options: champ.secondary_options }, required: champ.mandatory?, id: champ.input_id, aria: { describedby: champ.describedby_id } } + + = form.label :secondary_value, for: "#{champ.input_id}-secondary" do + = champ.drop_down_secondary_libelle.presence || "Valeur secondaire dépendant de la première" + - if champ.mandatory? + %span.mandatory * + - if champ.drop_down_secondary_description.present? + .notice{ id: "#{champ.describedby_id}-secondary" }= string_to_html(champ.drop_down_secondary_description) = form.select :secondary_value, champ.secondary_options[champ.primary_value], - { required: champ.mandatory? }, - { data: { secondary: true } } + {}, + { data: { secondary: true }, required: champ.mandatory?, id: "#{champ.input_id}-secondary", aria: { describedby: "#{champ.describedby_id}-secondary" } } diff --git a/app/views/shared/dossiers/editable_champs/_mesri.html.haml b/app/views/shared/dossiers/editable_champs/_mesri.html.haml index cf90abcb7..77d9e9453 100644 --- a/app/views/shared/dossiers/editable_champs/_mesri.html.haml +++ b/app/views/shared/dossiers/editable_champs/_mesri.html.haml @@ -4,4 +4,4 @@ %p.notice= t('.ine_notice') = form.text_field :ine, required: champ.mandatory?, - aria: { describedby: describedby_id(champ) } + aria: { describedby: champ.describedby_id } diff --git a/app/views/shared/dossiers/editable_champs/_multiple_drop_down_list.html.haml b/app/views/shared/dossiers/editable_champs/_multiple_drop_down_list.html.haml index d4f5c6788..5db86708c 100644 --- a/app/views/shared/dossiers/editable_champs/_multiple_drop_down_list.html.haml +++ b/app/views/shared/dossiers/editable_champs/_multiple_drop_down_list.html.haml @@ -3,10 +3,15 @@ = form.collection_check_boxes(:value, champ.enabled_non_empty_options, :to_s, :to_s) do |b| .editable-champ.editable-champ-checkbox = b.label do - = b.check_box({ multiple: true, checked: champ&.selected_options&.include?(b.value) }) + = b.check_box({ multiple: true, checked: champ&.selected_options&.include?(b.value), aria: { describedby: champ.describedby_id } }) = b.text - else - - hidden_field_id = SecureRandom.uuid - = form.hidden_field :value, { data: { uuid: hidden_field_id } } - = react_component("ComboMultipleDropdownList", options: champ.options, selected: champ.selected_options, disabled: champ.disabled_options, hiddenFieldId: hidden_field_id, label: champ.libelle) + = form.hidden_field :value + = react_component("ComboMultipleDropdownList", + options: champ.options, + selected: champ.selected_options, + disabled: champ.disabled_options, + id: champ.input_id, + labelledby: champ.labelledby_id, + describedby: champ.describedby_id) diff --git a/app/views/shared/dossiers/editable_champs/_number.html.haml b/app/views/shared/dossiers/editable_champs/_number.html.haml index d5aab710a..97b45497b 100644 --- a/app/views/shared/dossiers/editable_champs/_number.html.haml +++ b/app/views/shared/dossiers/editable_champs/_number.html.haml @@ -1,3 +1,5 @@ = form.number_field :value, + id: champ.input_id, + aria: { describedby: champ.describedby_id }, placeholder: champ.libelle, required: champ.mandatory? diff --git a/app/views/shared/dossiers/editable_champs/_pays.html.haml b/app/views/shared/dossiers/editable_champs/_pays.html.haml index 241049b46..975cfee94 100644 --- a/app/views/shared/dossiers/editable_champs/_pays.html.haml +++ b/app/views/shared/dossiers/editable_champs/_pays.html.haml @@ -1,4 +1,6 @@ -- hidden_field_id = SecureRandom.uuid -= form.hidden_field :value, { value: champ.localized_value, data: { uuid: hidden_field_id } } -= form.hidden_field :external_id, { data: { reference: true } } -= react_component("ComboPaysSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id) += form.hidden_field :value += form.hidden_field :external_id += react_component("ComboPaysSearch", + required: champ.mandatory?, + id: champ.input_id, + describedby: champ.describedby_id) diff --git a/app/views/shared/dossiers/editable_champs/_phone.html.haml b/app/views/shared/dossiers/editable_champs/_phone.html.haml index 888cdb944..289b1407d 100644 --- a/app/views/shared/dossiers/editable_champs/_phone.html.haml +++ b/app/views/shared/dossiers/editable_champs/_phone.html.haml @@ -2,6 +2,8 @@ -# very light validation is made client-side -# stronger validation is made server-side = form.phone_field :value, + id: champ.input_id, + aria: { describedby: champ.describedby_id }, placeholder: champ.libelle, required: champ.mandatory?, pattern: "[^a-z^A-Z]+" diff --git a/app/views/shared/dossiers/editable_champs/_pole_emploi.html.haml b/app/views/shared/dossiers/editable_champs/_pole_emploi.html.haml index c8a6dff46..1da67dcf5 100644 --- a/app/views/shared/dossiers/editable_champs/_pole_emploi.html.haml +++ b/app/views/shared/dossiers/editable_champs/_pole_emploi.html.haml @@ -4,4 +4,4 @@ %p.notice= t('.identifiant_notice') = form.text_field :identifiant, required: champ.mandatory?, - aria: { describedby: describedby_id(champ) } + aria: { describedby: champ.describedby_id } diff --git a/app/views/shared/dossiers/editable_champs/_regions.html.haml b/app/views/shared/dossiers/editable_champs/_regions.html.haml index 72d0d84f9..2dadcf48c 100644 --- a/app/views/shared/dossiers/editable_champs/_regions.html.haml +++ b/app/views/shared/dossiers/editable_champs/_regions.html.haml @@ -1,4 +1,6 @@ -- hidden_field_id = SecureRandom.uuid -= form.hidden_field :value, { data: { uuid: hidden_field_id } } -= form.hidden_field :external_id, { data: { reference: true } } -= react_component("ComboRegionsSearch", mandatory: champ.mandatory?, hiddenFieldId: hidden_field_id) += form.hidden_field :value += form.hidden_field :external_id += react_component("ComboRegionsSearch", + required: champ.mandatory?, + id: champ.input_id, + describedby: champ.describedby_id) diff --git a/app/views/shared/dossiers/editable_champs/_siret.html.haml b/app/views/shared/dossiers/editable_champs/_siret.html.haml index b62efa342..2fdcb3e9c 100644 --- a/app/views/shared/dossiers/editable_champs/_siret.html.haml +++ b/app/views/shared/dossiers/editable_champs/_siret.html.haml @@ -1,4 +1,6 @@ = form.text_field :value, + id: champ.input_id, + aria: { describedby: champ.describedby_id }, placeholder: champ.libelle, data: { remote: true, debounce: true, url: champs_siret_path(form.index), params: { champ_id: champ&.id }.to_query, spinner: true }, required: champ.mandatory?, diff --git a/app/views/shared/dossiers/editable_champs/_text.html.haml b/app/views/shared/dossiers/editable_champs/_text.html.haml index 3a4fc2db5..ff4aee988 100644 --- a/app/views/shared/dossiers/editable_champs/_text.html.haml +++ b/app/views/shared/dossiers/editable_champs/_text.html.haml @@ -1,4 +1,5 @@ = form.text_field :value, + id: champ.input_id, placeholder: champ.libelle, required: champ.mandatory?, - aria: { describedby: describedby_id(champ) } + aria: { describedby: champ.describedby_id } diff --git a/app/views/shared/dossiers/editable_champs/_textarea.html.haml b/app/views/shared/dossiers/editable_champs/_textarea.html.haml index a4666f22e..e1fc24cda 100644 --- a/app/views/shared/dossiers/editable_champs/_textarea.html.haml +++ b/app/views/shared/dossiers/editable_champs/_textarea.html.haml @@ -1,4 +1,6 @@ ~ form.text_area :value, + id: champ.input_id, + aria: { describedby: champ.describedby_id }, rows: 6, required: champ.mandatory?, value: html_to_string(champ.value) diff --git a/spec/controllers/champs/piece_justificative_controller_spec.rb b/spec/controllers/champs/piece_justificative_controller_spec.rb index 5c5fa202c..b279733b7 100644 --- a/spec/controllers/champs/piece_justificative_controller_spec.rb +++ b/spec/controllers/champs/piece_justificative_controller_spec.rb @@ -29,7 +29,7 @@ describe Champs::PieceJustificativeController, type: :controller do it 'renders the attachment template as Javascript' do subject expect(response.status).to eq(200) - expect(response.body).to include("editable-champ[data-champ-id=\"#{champ.id}\"]") + expect(response.body).to include("##{champ.input_group_id}") end end