diff --git a/app/assets/javascripts/protocols/new_protocol.js b/app/assets/javascripts/protocols/new_protocol.js index 3ef39fbb2..6d2085f3b 100644 --- a/app/assets/javascripts/protocols/new_protocol.js +++ b/app/assets/javascripts/protocols/new_protocol.js @@ -1,17 +1,7 @@ /* global dropdownSelector HelperModule */ (function() { const protocolModal = '#newProtocolModal'; - $(protocolModal) - .on('change', '#protocol_visibility', function() { - let checked = $(this)[0].checked; - $('#roleSelectWrapper').toggleClass('hidden', !checked); - $('#protocol_default_public_user_role_id').prop('disabled', !checked); - }) - .on('show.bs.modal', function() { - $(`${protocolModal} #protocol_name`).parent().removeClass('error'); - $(`${protocolModal} #protocol_name`).val(''); - $(this).find('.sci-input-field').focus(); - }); + const submitButton = $('.create-protocol-button'); let roleSelector = `${protocolModal} #protocol_role_selector`; dropdownSelector.init(roleSelector, { @@ -25,11 +15,22 @@ }); $(protocolModal) + .on('change', '#protocol_visibility', function() { + let checked = $(this)[0].checked; + $('#roleSelectWrapper').toggleClass('hidden', !checked); + $('#protocol_default_public_user_role_id').prop('disabled', !checked); + }) + .on('submit', function() { + submitButton.attr('disabled', 'disabled'); + }) .on('shown.bs.modal', function() { + $(`${protocolModal} #protocol_name`).parent().removeClass('error'); + $(`${protocolModal} #protocol_name`).val(''); $(this).find('.sci-input-field').focus(); }) .on('ajax:error', 'form', function(e, error) { let msg = error.responseJSON.error; + submitButton.removeAttr('disabled'); $(`${protocolModal} #protocol_name`).parent().addClass('error').attr('data-error-text', msg); }) .on('ajax:success', 'form', function(e, data) { @@ -37,6 +38,7 @@ HelperModule.flashAlertMsg(data.message, 'success'); } $(`${protocolModal} #protocol_name`).parent().removeClass('error'); + submitButton.removeAttr('disabled'); $(protocolModal).modal('hide'); }); }()); diff --git a/app/views/protocols/index/_new_protocol_modal.html.erb b/app/views/protocols/index/_new_protocol_modal.html.erb index 5dc3af264..d7af0698f 100644 --- a/app/views/protocols/index/_new_protocol_modal.html.erb +++ b/app/views/protocols/index/_new_protocol_modal.html.erb @@ -38,7 +38,7 @@