[Fix #2258] Validate options for linked dropdown menus

This commit is contained in:
Frederic Merizen 2018-09-12 15:19:05 +02:00
parent b521095010
commit 998754ab73
4 changed files with 82 additions and 6 deletions

View file

@ -3,6 +3,8 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
delegate :drop_down_list, to: :@type_de_champ
validate :check_presence_of_primary_options
def primary_options
primary_options = unpack_options.map(&:first)
if primary_options.present?
@ -21,6 +23,12 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
private
def check_presence_of_primary_options
if !PRIMARY_PATTERN.match?(drop_down_list.options.second)
errors.add(libelle, "doit commencer par une entrée de menu primaire de la forme <code style='white-space: pre-wrap;'>--texte--</code>")
end
end
def unpack_options
_, *options = drop_down_list.options
chunked = options.slice_before(PRIMARY_PATTERN)

View file

@ -1,6 +1,8 @@
class TypesDeChamp::TypeDeChampBase
include ActiveModel::Validations
delegate :libelle, to: :@type_de_champ
def initialize(type_de_champ)
@type_de_champ = type_de_champ
end