a11y(bloc-repetable.repetition): supprime une repetition via un bouton et non un lien

This commit is contained in:
Martin 2023-03-30 10:37:16 +02:00 committed by mfo
parent a3f1e1926a
commit 92d3f9c192
8 changed files with 24 additions and 4 deletions

View file

@ -0,0 +1,11 @@
# Display a form for destroying a repetition row via a button, but since it might already be nested within a form
# put this component before the actual form containing the editable champs
class EditableChamp::DeleteFormRepetitionRowComponent < ApplicationComponent
def self.form_id
ActionView::RecordIdentifier.dom_id(Champs::RepetitionChamp.new, :delete)
end
def call
form_tag('/champs/repetition/:id', method: :delete, data: { 'turbo-method': :delete, turbo: true }, id: self.class.form_id) {}
end
end

View file

@ -1,4 +1,3 @@
- # TODO, manage input id for focus on add repetition
- if @champ.options?
- if @champ.render_as_checkboxes?
= @form.collection_check_boxes(:value, @champ.enabled_non_empty_options, :to_s, :to_s) do |b|

View file

@ -0,0 +1,4 @@
---
en:
delete: Destroy element
delete_title: "Destroy the n°%{row_number} element"

View file

@ -0,0 +1,4 @@
---
fr:
delete: Supprimer lélément
delete_title: "Supprimer lélément n°%{row_number}"

View file

@ -5,5 +5,6 @@
= render EditableChamp::EditableChampComponent.new form: form, champ: champ, seen_at: @seen_at
.flex.row-reverse{ 'data-turbo': 'true' }
= link_to champs_repetition_path(@champ.id, row_id: @row.first.row_id), data: { turbo_method: :delete }, class: 'fr-btn fr-btn--sm fr-btn--tertiary fr-text-action-high--red-marianne' do
Supprimer lélément
= button_tag(name: "action", formaction: champs_repetition_path(@champ.id, row_id: @row.first.row_id), class: "fr-btn fr-btn--sm fr-btn--tertiary fr-text-action-high--red-marianne", title: t(".delete_title", row_number: @champ.rows.find_index(@row)), form: EditableChamp::DeleteFormRepetitionRowComponent.form_id) do
= t(".delete")

View file

@ -28,7 +28,6 @@ class Champs::RepetitionChamp < Champ
champs.group_by(&:row_id).values
end
def add_row(revision)
added_champs = []
transaction do

View file

@ -9,6 +9,7 @@
- form_options = { url: brouillon_dossier_url(dossier), method: :patch }
- else
- form_options = { url: modifier_dossier_url(dossier), method: :patch }
= render EditableChamp::DeleteFormRepetitionRowComponent.new
= render Attachment::DeleteFormComponent.new
= form_for dossier, form_options.merge({ html: { id: 'dossier-edit-form', class: 'form', multipart: true, novalidate: 'novalidate' } }) do |f|

View file

@ -1,6 +1,7 @@
.container.dossier-edit
- if dossier.champs_private.present?
%section.counter-start-header-section
= render EditableChamp::DeleteFormRepetitionRowComponent.new
= render Attachment::DeleteFormComponent.new
= form_for dossier, url: annotations_instructeur_dossier_path(dossier.procedure, dossier), html: { class: 'form', multipart: true } do |f|
- dossier.champs_private.each do |champ|