diff --git a/app/components/attachment/multiple_component.rb b/app/components/attachment/multiple_component.rb index fe9f42135..d9876570f 100644 --- a/app/components/attachment/multiple_component.rb +++ b/app/components/attachment/multiple_component.rb @@ -7,15 +7,17 @@ class Attachment::MultipleComponent < ApplicationComponent attr_reader :direct_upload attr_reader :id attr_reader :user_can_destroy + attr_reader :max delegate :count, :empty?, to: :attachments, prefix: true - def initialize(form:, attached_file:, user_can_destroy: false, direct_upload: true, id: nil) + def initialize(form:, attached_file:, user_can_destroy: false, direct_upload: true, id: nil, max: nil) @form = form @attached_file = attached_file @user_can_destroy = user_can_destroy @direct_upload = direct_upload @id = id + @max = max || 10 @attachments = attached_file.attachments || [] end @@ -28,7 +30,7 @@ class Attachment::MultipleComponent < ApplicationComponent return false if @attachments.empty? return false if !@attachments.last.persisted? - true + @attachments.count < @max end def stimulus_controller_name diff --git a/app/components/editable_champ/piece_justificative_component/piece_justificative_component.html.haml b/app/components/editable_champ/piece_justificative_component/piece_justificative_component.html.haml index 9805b2050..f9b2b2cb9 100644 --- a/app/components/editable_champ/piece_justificative_component/piece_justificative_component.html.haml +++ b/app/components/editable_champ/piece_justificative_component/piece_justificative_component.html.haml @@ -1,5 +1,5 @@ - user_can_destroy = !@champ.mandatory? || @champ.dossier.brouillon? -= render Attachment::MultipleComponent.new(form: @form, attached_file: @champ.piece_justificative_file, user_can_destroy: user_can_destroy) do |c| += render Attachment::MultipleComponent.new(form: @form, attached_file: @champ.piece_justificative_file, user_can_destroy: user_can_destroy, max: @champ.procedure&.piece_justificative_multiple == false ? 1 : nil) do |c| - if @champ.type_de_champ.piece_justificative_template&.attached? - c.with_template do %p