[#835] Enable html5 validation of multiple mails

This commit is contained in:
Frederic Merizen 2018-10-31 16:21:16 +01:00
parent c7358a8f53
commit 8cf235f2fd
4 changed files with 10 additions and 5 deletions

View file

@ -5,7 +5,12 @@ module CreateAvisConcern
def create_avis_from_params(dossier, confidentiel = false) def create_avis_from_params(dossier, confidentiel = false)
confidentiel ||= create_avis_params[:confidentiel] 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( create_results = Avis.create(
emails.map do |email| emails.map do |email|
@ -38,6 +43,6 @@ module CreateAvisConcern
end end
def create_avis_params def create_avis_params
params.require(:avis).permit(:emails, :introduction, :confidentiel) params.require(:avis).permit(:introduction, :confidentiel, emails: [])
end end
end end

View file

@ -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. %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| = 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 = 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 .flex.justify-between.align-baseline
- if must_be_confidentiel - if must_be_confidentiel

View file

@ -105,7 +105,7 @@ describe NewGestionnaire::AvisController, type: :controller do
let(:created_avis) { Avis.last } let(:created_avis) { Avis.last }
before do 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 end
context 'when an invalid email' do context 'when an invalid email' do

View file

@ -313,7 +313,7 @@ describe NewGestionnaire::DossiersController, type: :controller do
post :create_avis, params: { post :create_avis, params: {
procedure_id: procedure.id, procedure_id: procedure.id,
dossier_id: dossier.id, dossier_id: dossier.id,
avis: { emails: email, introduction: 'intro', confidentiel: true } avis: { emails: [email], introduction: 'intro', confidentiel: true }
} }
end end