diff --git a/app/validators/types_de_champ/expression_reguliere_validator.rb b/app/validators/types_de_champ/expression_reguliere_validator.rb index 39262adeb..3aaef80e7 100644 --- a/app/validators/types_de_champ/expression_reguliere_validator.rb +++ b/app/validators/types_de_champ/expression_reguliere_validator.rb @@ -4,7 +4,11 @@ class TypesDeChamp::ExpressionReguliereValidator < ActiveModel::EachValidator .flat_map { _1.repetition? ? procedure.draft_revision.children_of(_1) : _1 } .each do |tdc| if tdc.expression_reguliere? && tdc.invalid_regexp? - procedure.errors.add(:expression_reguliere, type_de_champ: tdc) + procedure.errors.add( + attribute, + procedure.errors.generate_message(attribute, :expression_reguliere_invalid, { value: tdc.libelle }), + type_de_champ: tdc + ) end end end diff --git a/config/locales/models/procedure/en.yml b/config/locales/models/procedure/en.yml index 34fc89e35..1328196b5 100644 --- a/config/locales/models/procedure/en.yml +++ b/config/locales/models/procedure/en.yml @@ -76,12 +76,14 @@ en: empty_repetition: 'requires at least one field' empty_drop_down: 'requires at least one option' inconsistent_header_section: "%{custom_message}" + expression_reguliere_invalid: "is invalid" draft_types_de_champ_private: format: 'Private field %{message}' invalid_condition: "have an invalid logic" empty_repetition: 'requires at least one field' empty_drop_down: 'requires at least one option' inconsistent_header_section: "%{custom_message}" + expression_reguliere_invalid: "is invalid" attestation_template: format: "%{attribute} %{message}" initiated_mail: diff --git a/config/locales/models/procedure/fr.yml b/config/locales/models/procedure/fr.yml index 5a9dfd9ab..35713d133 100644 --- a/config/locales/models/procedure/fr.yml +++ b/config/locales/models/procedure/fr.yml @@ -82,12 +82,14 @@ fr: empty_repetition: 'doit comporter au moins un champ répétable' empty_drop_down: 'doit comporter au moins un choix sélectionnable' inconsistent_header_section: "%{custom_message}" + expression_reguliere_invalid: "est invalide, veuillez la corriger" draft_types_de_champ_private: format: 'L’annotation privée %{message}' invalid_condition: "a une logique conditionnelle invalide" empty_repetition: 'doit comporter au moins un champ répétable' empty_drop_down: 'doit comporter au moins un choix sélectionnable' inconsistent_header_section: "%{custom_message}" + expression_reguliere_invalid: "est invalide, veuillez la corriger" attestation_template: format: "%{attribute} %{message}" initiated_mail: diff --git a/spec/components/procedures/errors_summary_spec.rb b/spec/components/procedures/errors_summary_spec.rb index ebeb1096d..06bf2c145 100644 --- a/spec/components/procedures/errors_summary_spec.rb +++ b/spec/components/procedures/errors_summary_spec.rb @@ -50,7 +50,8 @@ describe Procedure::ErrorsSummary, type: :component do { libelle: 'repetition requires children', type: :repetition, children: [] }, { libelle: 'drop down list requires options', type: :drop_down_list, options: [] }, { libelle: 'invalid condition', type: :text, condition: ds_eq(constant(true), constant(1)) }, - { libelle: 'header sections must have consistent order', type: :header_section, level: 2 } + { libelle: 'header sections must have consistent order', type: :header_section, level: 2 }, + { libelle: 'regexp invalid', type: :expression_reguliere, expression_reguliere_exemple_text: 'kthxbye', expression_reguliere: /{/ } ]) end @@ -70,6 +71,9 @@ describe Procedure::ErrorsSummary, type: :component do expect(page).to have_selector("a", text: "header sections must have consistent order") expect(page).to have_content("devrait être précédé d'un titre de niveau 1") + + expect(page).to have_selector("a", text: "regexp invalid") + expect(page).to have_content("est invalide, veuillez la corriger") end end