Permet de déposer un dossier lorsqu'un menu déroulant lié obligatoire n'a pas de valeur (car la liste est légitimement vide) dans le second champ.

This commit is contained in:
clemkeirua 2020-01-27 10:49:01 +01:00
parent 81fd91ce41
commit 65b4bcf3a1
2 changed files with 15 additions and 3 deletions

View file

@ -45,8 +45,9 @@ class Champs::LinkedDropDownListChamp < Champ
value.present? ? { primary: primary_value, secondary: secondary_value } : nil
end
def mandatory_and_blank?
mandatory? && (primary_value.blank? || secondary_value.blank?)
def blank?
primary_value.blank? ||
(has_secondary_options_for_primary? && secondary_value.blank?)
end
def search_terms
@ -58,4 +59,8 @@ class Champs::LinkedDropDownListChamp < Champ
def pack_value(primary, secondary)
self.value = JSON.generate([primary, secondary])
end
def has_secondary_options_for_primary?
primary_value.present? && secondary_options[primary_value].any?(&:present?)
end
end

View file

@ -91,7 +91,14 @@ describe Champs::LinkedDropDownListChamp do
end
context 'when there is a secondary value' do
before { subject.secondary_value = 'Primary' }
before { subject.secondary_value = 'Secondary' }
it { is_expected.not_to be_mandatory_and_blank }
end
context 'when there is nothing to select for the secondary value' do
let(:drop_down_list) { build(:drop_down_list, value: "--A--\nAbbott\nAbelard\n--B--\n--C--\nCynthia") }
before { subject.primary_value = 'B' }
it { is_expected.not_to be_mandatory_and_blank }
end