Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +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)
|
def check_condition(template)
|
||||||
if template['condition'].present?
|
if template['condition'].present?
|
||||||
CustomWizard::Mapper.new(
|
result = CustomWizard::Mapper.new(
|
||||||
inputs: template['condition'],
|
inputs: template['condition'],
|
||||||
user: @wizard.user,
|
user: @wizard.user,
|
||||||
data: @wizard.current_submission
|
data: @wizard.current_submission,
|
||||||
|
opts: {
|
||||||
|
multiple: true
|
||||||
|
}
|
||||||
).perform
|
).perform
|
||||||
|
|
||||||
|
result.any?
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,9 +45,8 @@ class CustomWizard::Mapper
|
||||||
def perform
|
def perform
|
||||||
multiple = @opts[:multiple]
|
multiple = @opts[:multiple]
|
||||||
perform_result = multiple ? [] : nil
|
perform_result = multiple ? [] : nil
|
||||||
input_size = inputs.size
|
|
||||||
|
|
||||||
inputs.each_with_index do |input, index|
|
inputs.each do |input|
|
||||||
input_type = input['type']
|
input_type = input['type']
|
||||||
pairs = input['pairs']
|
pairs = input['pairs']
|
||||||
|
|
||||||
|
@ -70,8 +69,6 @@ class CustomWizard::Mapper
|
||||||
|
|
||||||
if multiple
|
if multiple
|
||||||
perform_result.push(result)
|
perform_result.push(result)
|
||||||
elsif result != true && index < (input_size - 1)
|
|
||||||
next
|
|
||||||
else
|
else
|
||||||
perform_result = result
|
perform_result = result
|
||||||
break
|
break
|
||||||
|
|
|
@ -153,8 +153,11 @@ describe CustomWizard::Mapper do
|
||||||
expect(CustomWizard::Mapper.new(
|
expect(CustomWizard::Mapper.new(
|
||||||
inputs: inputs['validation_multiple_pairs'],
|
inputs: inputs['validation_multiple_pairs'],
|
||||||
data: data,
|
data: data,
|
||||||
user: user1
|
user: user1,
|
||||||
).perform).to eq(true)
|
opts: {
|
||||||
|
multiple: true
|
||||||
|
}
|
||||||
|
).perform.any?).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "validates the data when one of the conditions are met" do
|
it "validates the data when one of the conditions are met" do
|
||||||
|
@ -163,8 +166,11 @@ describe CustomWizard::Mapper do
|
||||||
expect(CustomWizard::Mapper.new(
|
expect(CustomWizard::Mapper.new(
|
||||||
inputs: inputs['validation_multiple_pairs'],
|
inputs: inputs['validation_multiple_pairs'],
|
||||||
data: custom_data,
|
data: custom_data,
|
||||||
user: user1
|
user: user1,
|
||||||
).perform).to eq(true)
|
opts: {
|
||||||
|
multiple: true
|
||||||
|
}
|
||||||
|
).perform.any?).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't validate the data when none of the conditions are met" do
|
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(
|
expect(CustomWizard::Mapper.new(
|
||||||
inputs: inputs['validation_multiple_pairs'],
|
inputs: inputs['validation_multiple_pairs'],
|
||||||
data: custom_data,
|
data: custom_data,
|
||||||
user: user1
|
user: user1,
|
||||||
).perform).to eq(false)
|
opts: {
|
||||||
|
multiple: true
|
||||||
|
}
|
||||||
|
).perform.any?).to eq(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren