Skip to content

Commit

Permalink
fix submit form
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBTurchyn committed Jul 8, 2023
1 parent 254aa9e commit dcbdc9e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/submit_form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def completed
private

def normalized_values
params[:values].to_unsafe_h.transform_values do |v|
params.fetch(:values, {}).to_unsafe_h.transform_values do |v|
if params[:cast_boolean] == 'true'
v == 'true'
else
Expand Down
20 changes: 10 additions & 10 deletions app/javascript/submission_form/form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
name="authenticity_token"
:value="authenticityToken"
>
<input
v-if="currentStep === stepFields.length - 1"
type="hidden"
name="completed"
value="true"
>
<input
value="put"
name="_method"
Expand Down Expand Up @@ -263,7 +257,7 @@
href="#"
class="inline border border-base-300 h-3 w-3 rounded-full mx-1"
:class="{ 'bg-base-300': index === currentStep, 'bg-base-content': index < currentStep || isCompleted, 'bg-white': index > currentStep }"
@click.prevent="isCompleted ? '' : goToStep(step, true)"
@click.prevent="isCompleted ? '' : [saveStep(), goToStep(step, true)]"
/>
</div>
</div>
Expand Down Expand Up @@ -401,13 +395,13 @@ export default {
}
})
},
saveStep () {
saveStep (formData) {
if (this.isCompleted) {
return Promise.resolve({})
} else {
return fetch(this.submitPath, {
method: 'POST',
body: new FormData(this.$refs.form)
body: formData || new FormData(this.$refs.form)
})
}
},
Expand All @@ -420,7 +414,13 @@ export default {
await stepPromise()
this.saveStep().then(response => {
const formData = new FormData(this.$refs.form)
if (this.currentStep === this.stepFields.length - 1) {
formData.append('completed', 'true')
}
this.saveStep(formData).then(response => {
const nextStep = this.stepFields[this.currentStep + 1]
if (nextStep) {
Expand Down
2 changes: 1 addition & 1 deletion app/views/submissions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
</div>
<% if submitter && !submitter.completed_at? %>
<div class="mt-2 mb-1">
<a class="btn btn-sm btn-primary w-full" target="_blank" href="<%= submit_form_url(slug: submitter.slug) %>">
<a class="btn btn-sm btn-primary w-full" target="_blank" href="<%= submit_form_path(slug: submitter.slug) %>">
Submit Form
</a>
</div>
Expand Down
2 changes: 2 additions & 0 deletions lib/submissions/generate_result_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def call(submitter)

value = submitter.values[field['uuid']]

next if Array.wrap(value).compact_blank.blank?

canvas = page.canvas(type: :overlay)

case field['type']
Expand Down

0 comments on commit dcbdc9e

Please sign in to comment.