[#835] Enable html5 validation of multiple mails
This commit is contained in:
parent
c7358a8f53
commit
8cf235f2fd
4 changed files with 10 additions and 5 deletions
|
@ -5,7 +5,12 @@ module CreateAvisConcern
|
|||
|
||||
def create_avis_from_params(dossier, confidentiel = false)
|
||||
confidentiel ||= create_avis_params[:confidentiel]
|
||||
emails = create_avis_params[:emails].split(',').map(&:strip)
|
||||
|
||||
# Because of a limitation of the email_field rails helper,
|
||||
# the :emails parameter is a 1-element array.
|
||||
# Hence the call to first
|
||||
# https://github.com/rails/rails/issues/17225
|
||||
emails = create_avis_params[:emails].first.split(',').map(&:strip)
|
||||
|
||||
create_results = Avis.create(
|
||||
emails.map do |email|
|
||||
|
@ -38,6 +43,6 @@ module CreateAvisConcern
|
|||
end
|
||||
|
||||
def create_avis_params
|
||||
params.require(:avis).permit(:emails, :introduction, :confidentiel)
|
||||
params.require(:avis).permit(:introduction, :confidentiel, emails: [])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
%p.avis-notice Les invités pourront consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais ils ne pourront pas le modifier.
|
||||
|
||||
= form_for avis, url: url, html: { class: 'form' } do |f|
|
||||
= f.text_field :emails, placeholder: 'Adresses email, séparées par des virgules', required: true
|
||||
= f.email_field :emails, placeholder: 'Adresses email, séparées par des virgules', required: true, multiple: true
|
||||
= f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
|
||||
.flex.justify-between.align-baseline
|
||||
- if must_be_confidentiel
|
||||
|
|
|
@ -105,7 +105,7 @@ describe NewGestionnaire::AvisController, type: :controller do
|
|||
let(:created_avis) { Avis.last }
|
||||
|
||||
before do
|
||||
post :create_avis, params: { id: previous_avis.id, avis: { emails: email, introduction: intro, confidentiel: asked_confidentiel } }
|
||||
post :create_avis, params: { id: previous_avis.id, avis: { emails: [email], introduction: intro, confidentiel: asked_confidentiel } }
|
||||
end
|
||||
|
||||
context 'when an invalid email' do
|
||||
|
|
|
@ -313,7 +313,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
|
|||
post :create_avis, params: {
|
||||
procedure_id: procedure.id,
|
||||
dossier_id: dossier.id,
|
||||
avis: { emails: email, introduction: 'intro', confidentiel: true }
|
||||
avis: { emails: [email], introduction: 'intro', confidentiel: true }
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue