Merge pull request #109 from paviliondev/conditional-submission
FIX: filter conditionally excluded fields from wizard submission
Dieser Commit ist enthalten in:
Commit
6cb5d62a7a
3 geänderte Dateien mit 50 neuen und 1 gelöschten Zeilen
|
@ -28,7 +28,7 @@ class CustomWizard::StepsController < ::ApplicationController
|
||||||
current_step = @wizard.find_step(update[:step_id])
|
current_step = @wizard.find_step(update[:step_id])
|
||||||
current_submission = @wizard.current_submission
|
current_submission = @wizard.current_submission
|
||||||
result = {}
|
result = {}
|
||||||
|
@wizard.filter_conditional_fields
|
||||||
if current_step.conditional_final_step && !current_step.last_step
|
if current_step.conditional_final_step && !current_step.last_step
|
||||||
current_step.force_final = true
|
current_step.force_final = true
|
||||||
end
|
end
|
||||||
|
|
|
@ -247,6 +247,26 @@ class CustomWizard::Wizard
|
||||||
set_submissions(submissions)
|
set_submissions(submissions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filter_conditional_fields
|
||||||
|
included_fields = steps.map { |s| s.fields.map { |f| f.id } }.flatten
|
||||||
|
filtered_submision = current_submission&.select do |key, _|
|
||||||
|
key = key.to_s
|
||||||
|
included_fields.include?(key) ||
|
||||||
|
required_fields.include?(key) ||
|
||||||
|
key.include?("action")
|
||||||
|
end
|
||||||
|
|
||||||
|
save_submission(filtered_submision)
|
||||||
|
end
|
||||||
|
|
||||||
|
def required_fields
|
||||||
|
%w{
|
||||||
|
submitted_at
|
||||||
|
route_to
|
||||||
|
saved_param
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def final_cleanup!
|
def final_cleanup!
|
||||||
if id == user.custom_fields['redirect_to_wizard']
|
if id == user.custom_fields['redirect_to_wizard']
|
||||||
user.custom_fields.delete('redirect_to_wizard')
|
user.custom_fields.delete('redirect_to_wizard')
|
||||||
|
|
|
@ -249,4 +249,33 @@ describe CustomWizard::StepsController do
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.parsed_body['final']).to eq(true)
|
expect(response.parsed_body['final']).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "excludes the non-included conditional fields from the submissions" do
|
||||||
|
new_template = wizard_template.dup
|
||||||
|
new_template['steps'][1]['fields'][0]['condition'] = wizard_field_condition_template['condition']
|
||||||
|
CustomWizard::Template.save(new_template, skip_jobs: true)
|
||||||
|
|
||||||
|
put '/w/super-mega-fun-wizard/steps/step_1.json', params: {
|
||||||
|
fields: {
|
||||||
|
step_1_field_1: "Condition will pass"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
put '/w/super-mega-fun-wizard/steps/step_2.json', params: {
|
||||||
|
fields: {
|
||||||
|
step_2_field_1: "1995-04-23"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
put '/w/super-mega-fun-wizard/steps/step_1.json', params: {
|
||||||
|
fields: {
|
||||||
|
step_1_field_1: "Condition will not pass"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wizard_id = response.parsed_body['wizard']['id']
|
||||||
|
wizard = CustomWizard::Wizard.create(wizard_id, user)
|
||||||
|
submission = wizard.submissions.last
|
||||||
|
expect(submission.keys).not_to include("step_2_field_1")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren