From 91d5fb906a589e7a6d53cde3d35ebee2e58a2095 Mon Sep 17 00:00:00 2001 From: Arthur ZHU Date: Fri, 10 Jun 2022 15:54:33 +0200 Subject: [PATCH] =?UTF-8?q?am=C3=A9lioration=20erreurs=20formulaire=20dyna?= =?UTF-8?q?mique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/entreprises/forms.py | 13 ++++++++--- app/static/css/entreprises.css | 2 +- .../entreprises/ajout_correspondants.html | 22 ++++++++++++++++--- .../entreprises/envoi_offre_form.html | 16 +++++++------- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index c564b24d..61d517b7 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -471,6 +471,7 @@ class CorrespondantModificationForm(FlaskForm): if not self.telephone.data and not self.mail.data: msg = "Saisir un moyen de contact (mail ou téléphone)" self.telephone.errors.append(msg) + self.mail.errors.append(msg) validate = False return validate @@ -690,7 +691,7 @@ class TaxeApprentissageModificationForm(FlaskForm): class EnvoiOffreForm(FlaskForm): responsables = FieldList( - _build_string_field( + StringField( "Responsable (*)", render_kw={ "placeholder": "Tapez le nom du responsable de formation", @@ -703,6 +704,8 @@ class EnvoiOffreForm(FlaskForm): def validate(self): validate = True + list_select = True + if not FlaskForm.validate(self): validate = False @@ -718,8 +721,12 @@ class EnvoiOffreForm(FlaskForm): .first() ) if responsable is None: - entry.errors.append("Champ incorrect (selectionnez dans la liste)") - validate = False + validate, list_select = False, False + + if list_select is False: + self.responsables.errors.append( + "Champ incorrect (selectionnez dans la liste)" + ) return validate diff --git a/app/static/css/entreprises.css b/app/static/css/entreprises.css index 14c8f210..45d3f762 100644 --- a/app/static/css/entreprises.css +++ b/app/static/css/entreprises.css @@ -131,7 +131,7 @@ margin-right: 20px; } -.title-form { +.title-form-error { font-weight: bold; color: #a94442 } \ No newline at end of file diff --git a/app/templates/entreprises/ajout_correspondants.html b/app/templates/entreprises/ajout_correspondants.html index 48791603..fd0fe64b 100644 --- a/app/templates/entreprises/ajout_correspondants.html +++ b/app/templates/entreprises/ajout_correspondants.html @@ -16,9 +16,10 @@

{{ form.hidden_tag() }} + {{ form.correspondants.label }} {% for subfield in form.correspondants %} - {% if form.correspondants.errors %} -

Formulaire Correspondants-{{ loop.index-1 }}

+ {% if subfield.errors %} +

Formulaire {{ subfield.label.text }}

{% endif %} {% for subsubfield in subfield %} {% if subsubfield.errors %} @@ -59,7 +60,22 @@ } let newFieldName = `correspondants-${Math.max(...correspondantInputIds) + 1}`; allCorrepondantsFieldWrapper.insertAdjacentHTML('beforeend',` -
  • Retirer ce correspondant
  • +
  • + + + + + + + + + + + +
    + +
    Retirer ce correspondant
    +
  • `); }); } diff --git a/app/templates/entreprises/envoi_offre_form.html b/app/templates/entreprises/envoi_offre_form.html index 6ead6477..e8f2d55e 100644 --- a/app/templates/entreprises/envoi_offre_form.html +++ b/app/templates/entreprises/envoi_offre_form.html @@ -18,13 +18,9 @@

    {{ form.hidden_tag() }} - {{ form.responsables.label }}
    - {% for subfield in form.responsables %} - {% if subfield.errors %} - {% for error in subfield.errors %} -

    {{ error }}

    - {% endfor %} - {% endif %} + {{ form.responsables.label }} + {% for error in form.responsables.errors %} +

    {{ error }}

    {% endfor %} {{ form.responsables }}
    @@ -71,7 +67,11 @@ } let newFieldName = `responsables-${Math.max(...responsableInputIds) + 1}`; allResponsablesFieldWrapper.insertAdjacentHTML('beforeend',` -
  • Retirer
  • +
  • + + +
    Retirer
    +
  • `); var as_r = new bsn.AutoSuggest(newFieldName, responsables_options); });