Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jl - Disabling submit button to prevent multiple form submissions #275

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/assets/javascripts/study_level_activities.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ $ ->
$.ajax
type: 'GET'
url: "/fulfillments/#{fulfillment_id}/edit"

$(document).on 'click', '.add_fulfillment', ->
$('.add_fulfillment').prop('disabled', true)
$('.fulfillment-form').submit()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this? Won't it continue down the normal submit path?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it will still submit the form. But disabling the button prevents the user from creating multiple fulfillments. Before you could rapid click and create like 6 of them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried just disabling the button without the $('.fulfillment-form').submit(), but the form would not submit in that case. I needed to do the manual submit after the disable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, sounds good.

4 changes: 2 additions & 2 deletions app/views/study_level_activities/_fulfillment_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

.modal-dialog
.modal-content
= form_for fulfillment, {remote: true, html: {class: "form-horizontal", role: "form"}} do |form|
= form_for fulfillment, {remote: true, html: {class: "form-horizontal fulfillment-form", role: "form"}} do |form|
.modal-header
%button.close{type: 'button', data: {dismiss: 'modal'}}
%span{aria: {hidden:'true'}} ×
Expand Down Expand Up @@ -54,4 +54,4 @@
.center-block
%button#fulfillments_back.btn.btn-default{type: 'button', data: {line_item_id: fulfillment.line_item_id}}
= t(:actions)[:close]
%input.btn.btn-primary{type: 'submit', value: t(:actions)[:save]}
%input.btn.btn-primary.add_fulfillment{type: 'submit', value: t(:actions)[:save]}