diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e45d95781..acdabec8a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,6 +49,15 @@ module ApplicationHelper end end + def render_champ(champ) + champ_selector = ".editable-champ[data-champ-id=\"#{champ.id}\"]" + form_html = render 'shared/dossiers/edit', dossier: champ.dossier, apercu: false + champ_html = Nokogiri::HTML.fragment(form_html).at_css(champ_selector).to_s + # rubocop:disable Rails/OutputSafety + raw("document.querySelector('#{champ_selector}').outerHTML = \"#{escape_javascript(champ_html)}\";") + # rubocop:enable Rails/OutputSafety + end + def remove_element(selector, timeout: 0, inner: false) script = "(function() {"; script << "var el = document.querySelector('#{selector}');" diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index 3eb709454..1e51c662d 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -33,7 +33,7 @@ module ChampHelper end def auto_attach_url(form, object) - if feature_enabled?(:autoupload_dossier_attachments) && object.is_a?(Champ) && object.public? + if feature_enabled?(:autoupload_dossier_attachments) && object.is_a?(Champ) && object.persisted? && object.public? champs_piece_justificative_url(object.id) end end diff --git a/app/views/champs/piece_justificative/show.js.erb b/app/views/champs/piece_justificative/show.js.erb index e921f9556..80b454204 100644 --- a/app/views/champs/piece_justificative/show.js.erb +++ b/app/views/champs/piece_justificative/show.js.erb @@ -1,15 +1,4 @@ -<% dossier = @champ.dossier %> - -<%= fields_for dossier do |form| %> - <%= form.fields_for :champs, dossier.champs.where(id: @champ.id), include_id: false do |champ_form| %> - <% render_to_element(".editable-champ[data-champ-id=\"#{@champ.id}\"]", - partial: 'shared/dossiers/editable_champs/editable_champ', - locals: { - champ: @champ, - form: champ_form - }) %> - <% end %> -<% end %> +<%= render_champ(@champ) %> <% attachment = @champ.piece_justificative_file.attachment %> <% if attachment.virus_scanner.pending? %>