no more empty case

This commit is contained in:
simon lehericey 2024-09-18 16:30:16 +02:00
parent 5a19cc1a09
commit 77b754a08d
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 4 additions and 9 deletions

View file

@ -481,12 +481,10 @@ class TypeDeChamp < ApplicationRecord
end
def drop_down_list_enabled_non_empty_options(other: false)
list_options = drop_down_options.reject(&:empty?)
if other && drop_down_other?
list_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]]
drop_down_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]]
else
list_options
drop_down_options
end
end

View file

@ -89,9 +89,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
end
def unpack_options
chunked = drop_down_options
.reject(&:empty?) # TODO: remove after removing empty options
.slice_before(PRIMARY_PATTERN)
chunked = drop_down_options.slice_before(PRIMARY_PATTERN)
chunked.map do |chunk|
primary, *secondary = chunk
@ -101,8 +99,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
end
def check_presence_of_primary_options
# TODO: replace by `drop_down_options.first` when the empty options are removed
if !PRIMARY_PATTERN.match?(drop_down_options.find(&:present?))
if !PRIMARY_PATTERN.match?(drop_down_options.first)
errors.add(libelle.presence || "La liste", "doit commencer par une entrée de menu primaire de la forme <code style='white-space: pre-wrap;'>--texte--</code>")
end
end