remove default empty value in drop_down_list
This commit is contained in:
parent
51e192939c
commit
061c9cc6f3
6 changed files with 11 additions and 10 deletions
|
@ -496,10 +496,8 @@ class TypeDeChamp < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
DEFAULT_EMPTY = ['']
|
||||
def drop_down_list_value=(value)
|
||||
split = value.to_s.lines.map(&:strip).reject(&:empty?)
|
||||
self.drop_down_options = split.blank? ? [] : DEFAULT_EMPTY + split
|
||||
self.drop_down_options = value.to_s.lines.map(&:strip).reject(&:empty?)
|
||||
end
|
||||
|
||||
def header_section_level_value
|
||||
|
|
|
@ -89,8 +89,10 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
|||
end
|
||||
|
||||
def unpack_options
|
||||
_, *options = drop_down_options
|
||||
chunked = options.slice_before(PRIMARY_PATTERN)
|
||||
chunked = drop_down_options
|
||||
.reject(&:empty?) # TODO: remove after removing empty options
|
||||
.slice_before(PRIMARY_PATTERN)
|
||||
|
||||
chunked.map do |chunk|
|
||||
primary, *secondary = chunk
|
||||
secondary = add_blank_option_when_not_mandatory(secondary)
|
||||
|
@ -99,7 +101,8 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
|||
end
|
||||
|
||||
def check_presence_of_primary_options
|
||||
if !PRIMARY_PATTERN.match?(drop_down_options.second)
|
||||
# TODO: replace by `drop_down_options.first` when the empty options are removed
|
||||
if !PRIMARY_PATTERN.match?(drop_down_options.find(&:present?))
|
||||
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
|
||||
|
|
|
@ -96,7 +96,7 @@ FactoryBot.define do
|
|||
end
|
||||
factory :type_de_champ_linked_drop_down_list do
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) }
|
||||
drop_down_list_value { "--primary--\nsecondary\n" }
|
||||
drop_down_list_value { "--primary--\r\nsecondary\n" }
|
||||
end
|
||||
factory :type_de_champ_expression_reguliere do
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:expression_reguliere) }
|
||||
|
|
|
@ -78,7 +78,7 @@ describe Champs::LinkedDropDownListChamp do
|
|||
end
|
||||
|
||||
describe '#mandatory_and_blank' do
|
||||
let(:value) { "--Primary--\nSecondary" }
|
||||
let(:value) { "--Primary--\r\nSecondary" }
|
||||
|
||||
subject { described_class.new }
|
||||
before { allow(subject).to receive(:type_de_champ).and_return(type_de_champ) }
|
||||
|
|
|
@ -203,7 +203,7 @@ describe TypeDeChamp do
|
|||
expect(type_de_champ.drop_down_options).to eq([])
|
||||
|
||||
type_de_champ.drop_down_list_value = " 1 / 2 \r\n 3"
|
||||
expect(type_de_champ.drop_down_options).to eq(['', '1 / 2', '3'])
|
||||
expect(type_de_champ.drop_down_options).to eq(['1 / 2', '3'])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ describe 'As an administrateur I can edit types de champ', js: true do
|
|||
fill_in 'Options de la liste', with: 'Un menu', fill_options: { clear: :backspace }
|
||||
check "Proposer une option « autre » avec un texte libre"
|
||||
|
||||
wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_options == ['', 'Un menu'] }
|
||||
wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_options == ['Un menu'] }
|
||||
wait_until { procedure.active_revision.types_de_champ_public.first.drop_down_other == "1" }
|
||||
expect(page).to have_content('Formulaire enregistré')
|
||||
|
||||
|
|
Loading…
Reference in a new issue