Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 01:10:28 +01:00
use option multiple and aggregate the result
Dieser Commit ist enthalten in:
Ursprung
be1eab6092
Commit
eb93169f86
3 geänderte Dateien mit 23 neuen und 12 gelöschten Zeilen
|
@ -192,11 +192,16 @@ class CustomWizard::Builder
|
|||
|
||||
def check_condition(template)
|
||||
if template['condition'].present?
|
||||
CustomWizard::Mapper.new(
|
||||
result = CustomWizard::Mapper.new(
|
||||
inputs: template['condition'],
|
||||
user: @wizard.user,
|
||||
data: @wizard.current_submission
|
||||
data: @wizard.current_submission,
|
||||
opts: {
|
||||
multiple: true
|
||||
}
|
||||
).perform
|
||||
|
||||
result.any?
|
||||
else
|
||||
true
|
||||
end
|
||||
|
|
|
@ -45,9 +45,8 @@ class CustomWizard::Mapper
|
|||
def perform
|
||||
multiple = @opts[:multiple]
|
||||
perform_result = multiple ? [] : nil
|
||||
input_size = inputs.size
|
||||
|
||||
inputs.each_with_index do |input, index|
|
||||
inputs.each do |input|
|
||||
input_type = input['type']
|
||||
pairs = input['pairs']
|
||||
|
||||
|
@ -70,8 +69,6 @@ class CustomWizard::Mapper
|
|||
|
||||
if multiple
|
||||
perform_result.push(result)
|
||||
elsif result != true && index < (input_size - 1)
|
||||
next
|
||||
else
|
||||
perform_result = result
|
||||
break
|
||||
|
|
|
@ -153,8 +153,11 @@ describe CustomWizard::Mapper do
|
|||
expect(CustomWizard::Mapper.new(
|
||||
inputs: inputs['validation_multiple_pairs'],
|
||||
data: data,
|
||||
user: user1
|
||||
).perform).to eq(true)
|
||||
user: user1,
|
||||
opts: {
|
||||
multiple: true
|
||||
}
|
||||
).perform.any?).to eq(true)
|
||||
end
|
||||
|
||||
it "validates the data when one of the conditions are met" do
|
||||
|
@ -163,8 +166,11 @@ describe CustomWizard::Mapper do
|
|||
expect(CustomWizard::Mapper.new(
|
||||
inputs: inputs['validation_multiple_pairs'],
|
||||
data: custom_data,
|
||||
user: user1
|
||||
).perform).to eq(true)
|
||||
user: user1,
|
||||
opts: {
|
||||
multiple: true
|
||||
}
|
||||
).perform.any?).to eq(true)
|
||||
end
|
||||
|
||||
it "doesn't validate the data when none of the conditions are met" do
|
||||
|
@ -174,8 +180,11 @@ describe CustomWizard::Mapper do
|
|||
expect(CustomWizard::Mapper.new(
|
||||
inputs: inputs['validation_multiple_pairs'],
|
||||
data: custom_data,
|
||||
user: user1
|
||||
).perform).to eq(false)
|
||||
user: user1,
|
||||
opts: {
|
||||
multiple: true
|
||||
}
|
||||
).perform.any?).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Laden …
In neuem Issue referenzieren