fix(tdc.expression_reguliere): invalid regexp shows nice error message

This commit is contained in:
mfo 2024-07-15 09:59:50 +02:00
parent 29d36973ba
commit 19268345db
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
4 changed files with 12 additions and 1 deletions

View file

@ -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

View file

@ -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:

View file

@ -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: 'Lannotation 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:

View file

@ -71,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