refactor(champ): improuve repetition champ

This commit is contained in:
Paul Chavard 2022-05-03 16:40:09 +02:00
parent 196a9b9a98
commit 1a9f2f0eef
11 changed files with 21 additions and 55 deletions

View file

@ -1,12 +1,8 @@
.repetition
.repetition{ id: dom_id(champ, :rows) }
- champ.rows.each do |champs|
= render partial: 'shared/dossiers/editable_champs/repetition_row', locals: { form: form, champ: champ, row: champs }
- if champ.persisted?
= link_to champs_repetition_path(champ.id), class: 'button add-row', data: { remote: true, disable: true, method: 'POST' } do
%span.icon.add
Ajouter un élément pour « #{champ.libelle} »
- else
%a.button.add-row
.actions{ 'data-turbo': 'true' }
= button_tag type: :submit, form: :turbo_form, formaction: champs_repetition_path(champ.id), formmethod: :post, class: 'button add-row' do
%span.icon.add
Ajouter un élément pour « #{champ.libelle} »

View file

@ -1,13 +1,9 @@
- row_dom_id = "row-#{SecureRandom.hex(4)}"
.row{ id: row_dom_id }
-# Tell the controller which DOM element should be removed once the row deletion is successful
= hidden_field_tag 'deleted_row_dom_ids[]', row_dom_id, disabled: true
- row.each do |champ|
= fields_for champ.input_name, champ do |form|
= render partial: 'shared/dossiers/editable_champs/editable_champ', locals: { form: form, champ: champ }
= form.hidden_field :_destroy, disabled: true
.flex.row-reverse
%button.button.danger.remove-row{ type: :button }
.flex.row-reverse{ 'data-turbo': 'true' }
= button_tag type: :submit, form: :turbo_form, formaction: champs_repetition_path(champ.id, champ_ids: row.map(&:id), row_id: row_dom_id), formmethod: :delete, class: 'button danger remove-row' do
Supprimer lélément