FIX: exclude conditional fields while saving step submission
Dieser Commit ist enthalten in:
Ursprung
8c61b9b1f3
Commit
ff14570d64
3 geänderte Dateien mit 6 neuen und 13 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
|
||||||
|
|
|
@ -243,19 +243,20 @@ class CustomWizard::Wizard
|
||||||
return nil unless save_submissions
|
return nil unless save_submissions
|
||||||
|
|
||||||
submissions.pop(1) if unfinished?
|
submissions.pop(1) if unfinished?
|
||||||
submission = filter_conditional_fields(submission)
|
|
||||||
submissions.push(submission)
|
submissions.push(submission)
|
||||||
set_submissions(submissions)
|
set_submissions(submissions)
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_conditional_fields(submission)
|
def filter_conditional_fields
|
||||||
included_fields = steps.map { |s| s.fields.map { |f| f.id } }.flatten
|
included_fields = steps.map { |s| s.fields.map { |f| f.id } }.flatten
|
||||||
submission.select do |key, _|
|
filtered_submision = current_submission&.select do |key, _|
|
||||||
key = key.to_s
|
key = key.to_s
|
||||||
included_fields.include?(key) ||
|
included_fields.include?(key) ||
|
||||||
required_fields.include?(key) ||
|
required_fields.include?(key) ||
|
||||||
key.include?("action")
|
key.include?("action")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
save_submission(filtered_submision)
|
||||||
end
|
end
|
||||||
|
|
||||||
def required_fields
|
def required_fields
|
||||||
|
|
|
@ -272,16 +272,8 @@ describe CustomWizard::StepsController do
|
||||||
step_1_field_1: "Condition will not pass"
|
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).to include("step_2_field_1")
|
|
||||||
|
|
||||||
put '/w/super-mega-fun-wizard/steps/step_2.json', params: {
|
wizard_id = response.parsed_body['wizard']['id']
|
||||||
fields: {
|
|
||||||
step_2_field_1: "1995-04-23"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wizard = CustomWizard::Wizard.create(wizard_id, user)
|
wizard = CustomWizard::Wizard.create(wizard_id, user)
|
||||||
submission = wizard.submissions.last
|
submission = wizard.submissions.last
|
||||||
expect(submission.keys).not_to include("step_2_field_1")
|
expect(submission.keys).not_to include("step_2_field_1")
|
||||||
|
|
Laden …
In neuem Issue referenzieren