1

I would like to disable the submit button once the form has been submitted. That means the submit button should not be clickable after the user click submit. That means I want the submit button to remain disable even after refresh

; (function ($) {

    $.fn.tpFormDialogCustom = function (method) {

        var self = this;

        var dialogButtons = [
          {
              text: "Submit and Email",
              id: "tpFormDialog_btnSubmit",
              click: submitandmailTpFormDialog
          },


function submitandmailTpFormDialog() {
  if(CheckValidate()) {
    commonDialogs.showError(ExampleMessages.JournalError);
  } else {
    commonDialogs.showConfirm(ExampleMessages.ConfirmEmail, function() {
      try {
        commonDialogs.showProgress(ExampleMessages.SubmitAndEmail);
        var o = getOptions();
        var form = $(o.form);
        form.ajaxSubmit({
          success: handleEmailResponse,
          beforeSerialize: function($form, options) {
            if(!$("#SubmitBtn", $form).length) {
              $('select.required', $form).prop('disabled', false);
              $form.append("<input id='SubmitBtn' type='hidden' name='From' value='Submit' />");
            }
          }
        });
      } catch(e) {
        commonDialogs.showError();
      }
    });
  }
}


function handleEmailResponse(data) {
            $('#tpFormDialog_btnSubmit').prop("disabled", true);
            commonDialogs.hideProgress();
            var o = getOptions();
            if (data.IsSuccess) {
                commonDialogs.showAck(ExampleMessages.ConfirmSendEmail);
                closeTpFormDialog();
                o.table.refresh();
            } else {
                var errors = data.ResponseModel;
                if (typeof (errors) === 'string') {
                    commonDialogs.showError(errors);
                } else {
                    helpForValidation.showErrors(errors);
                }
            }
        };
2
  • I usually hide my submit buttons with display none on click and replace them with a 'thank you for contacting us' type message. Commented Aug 28, 2016 at 10:35
  • Possible duplicate of Jquery disable button (popup dialog) Commented Aug 29, 2016 at 2:17

2 Answers 2

3

You can disable your submit button by adding disable property to submit button.

$('input:submit').click(function(){
    console.log("Form is submiting.....");
    $('input:submit').attr("disabled", true);
});

Demo : https://jsfiddle.net/Prakash_Thete/6qqgszs4/

Sign up to request clarification or add additional context in comments.

Comments

2

You should do it on ajax success so in case of error the user can re submit the form. In your case it would be inside the handleEmailResponse function.

function handleMailResponse(){
    $('#btnSubmitId').prop("disabled", true);

    /* the rest of your code */
}

4 Comments

Hi, i added it to the handlemailresponse but it doesn't seems to work. The updated answer is at the top.
$('tpFormDialog_btnSubmit').prop("disabled", true); should be $('#tpFormDialog_btnSubmit').prop("disabled", true); with a hash # if it is declared as id <button id="tpFormDialog_btnSubmit"></button>
added #. still not working. I want the submit button to remain disable after refresh.
if the button is disabled after refresh how user will be able to delete an item ?? that makes no sense

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.