How can I disable double click on Jquery Modal Dialog button?












2















I’m using Jquery Modal Dialog for submitting some data into the server side and after that saving into database; here my modal dialog code is:



    function loadUserDialog(tag, event, target, id) {
event.preventDefault();

$.validator.unobtrusive.parse('#frmModalPopup');

var $loading = $('<img src="@Url.Content("~/Content/images/ajaxLoading.gif")" alt="loading" class="ui-loading-icon" style="margin: 150px 150px;">');
var $url = $(tag).attr('href');
var $title = $(tag).attr('title');
var $dialog = $('<div></div>');
$dialog.empty();
$dialog
.append($loading)
.load($url)
.dialog({
autoOpen: false
, title: $title
, width: 500
, modal: true
, minHeight: 400
, show: 'fade'
, hide: 'fade'
});
$dialog.dialog("option", "buttons", {
"Submit": function () {
var dlg = $(this);
if (IsValidUserName() && $('#frmModalPopup').validate().form()) {
$.ajax({
url: $url,
type: 'POST',
data: $(target).serialize(),
success: function (response) {
var cid = $(response).attr('id');
if (cid != null && cid != undefined) {
$(response).fadeIn('slow').appendTo(id);
$(window).scrollTop($('#' + cid).offset().top);
}

dlg.dialog('close');
dlg.empty();
},
error: function (xhr) {
alertMessage("EmailId is already in use!");
$.validator.unobtrusive.parse('#frmModalPopup');
}
});
}
},
"Cancel": function () {
$(this).dialog('close');
$(this).empty();
}
});

$dialog.dialog('open');
};


But when I do multiple clicks on Submit button at time (more than once) then form is submitted more than once and I got duplicate data submission information. So could you please tell me how to disable double click or more than once click on button Submit.










share|improve this question

























  • all you had were .net and mvc tags. No jquery tag at all!

    – Valamas
    Mar 21 '13 at 11:48











  • How does stop prevent the submit firing twice?

    – Liam
    Mar 21 '13 at 11:53
















2















I’m using Jquery Modal Dialog for submitting some data into the server side and after that saving into database; here my modal dialog code is:



    function loadUserDialog(tag, event, target, id) {
event.preventDefault();

$.validator.unobtrusive.parse('#frmModalPopup');

var $loading = $('<img src="@Url.Content("~/Content/images/ajaxLoading.gif")" alt="loading" class="ui-loading-icon" style="margin: 150px 150px;">');
var $url = $(tag).attr('href');
var $title = $(tag).attr('title');
var $dialog = $('<div></div>');
$dialog.empty();
$dialog
.append($loading)
.load($url)
.dialog({
autoOpen: false
, title: $title
, width: 500
, modal: true
, minHeight: 400
, show: 'fade'
, hide: 'fade'
});
$dialog.dialog("option", "buttons", {
"Submit": function () {
var dlg = $(this);
if (IsValidUserName() && $('#frmModalPopup').validate().form()) {
$.ajax({
url: $url,
type: 'POST',
data: $(target).serialize(),
success: function (response) {
var cid = $(response).attr('id');
if (cid != null && cid != undefined) {
$(response).fadeIn('slow').appendTo(id);
$(window).scrollTop($('#' + cid).offset().top);
}

dlg.dialog('close');
dlg.empty();
},
error: function (xhr) {
alertMessage("EmailId is already in use!");
$.validator.unobtrusive.parse('#frmModalPopup');
}
});
}
},
"Cancel": function () {
$(this).dialog('close');
$(this).empty();
}
});

$dialog.dialog('open');
};


But when I do multiple clicks on Submit button at time (more than once) then form is submitted more than once and I got duplicate data submission information. So could you please tell me how to disable double click or more than once click on button Submit.










share|improve this question

























  • all you had were .net and mvc tags. No jquery tag at all!

    – Valamas
    Mar 21 '13 at 11:48











  • How does stop prevent the submit firing twice?

    – Liam
    Mar 21 '13 at 11:53














2












2








2








I’m using Jquery Modal Dialog for submitting some data into the server side and after that saving into database; here my modal dialog code is:



    function loadUserDialog(tag, event, target, id) {
event.preventDefault();

$.validator.unobtrusive.parse('#frmModalPopup');

var $loading = $('<img src="@Url.Content("~/Content/images/ajaxLoading.gif")" alt="loading" class="ui-loading-icon" style="margin: 150px 150px;">');
var $url = $(tag).attr('href');
var $title = $(tag).attr('title');
var $dialog = $('<div></div>');
$dialog.empty();
$dialog
.append($loading)
.load($url)
.dialog({
autoOpen: false
, title: $title
, width: 500
, modal: true
, minHeight: 400
, show: 'fade'
, hide: 'fade'
});
$dialog.dialog("option", "buttons", {
"Submit": function () {
var dlg = $(this);
if (IsValidUserName() && $('#frmModalPopup').validate().form()) {
$.ajax({
url: $url,
type: 'POST',
data: $(target).serialize(),
success: function (response) {
var cid = $(response).attr('id');
if (cid != null && cid != undefined) {
$(response).fadeIn('slow').appendTo(id);
$(window).scrollTop($('#' + cid).offset().top);
}

dlg.dialog('close');
dlg.empty();
},
error: function (xhr) {
alertMessage("EmailId is already in use!");
$.validator.unobtrusive.parse('#frmModalPopup');
}
});
}
},
"Cancel": function () {
$(this).dialog('close');
$(this).empty();
}
});

$dialog.dialog('open');
};


But when I do multiple clicks on Submit button at time (more than once) then form is submitted more than once and I got duplicate data submission information. So could you please tell me how to disable double click or more than once click on button Submit.










share|improve this question
















I’m using Jquery Modal Dialog for submitting some data into the server side and after that saving into database; here my modal dialog code is:



    function loadUserDialog(tag, event, target, id) {
event.preventDefault();

$.validator.unobtrusive.parse('#frmModalPopup');

var $loading = $('<img src="@Url.Content("~/Content/images/ajaxLoading.gif")" alt="loading" class="ui-loading-icon" style="margin: 150px 150px;">');
var $url = $(tag).attr('href');
var $title = $(tag).attr('title');
var $dialog = $('<div></div>');
$dialog.empty();
$dialog
.append($loading)
.load($url)
.dialog({
autoOpen: false
, title: $title
, width: 500
, modal: true
, minHeight: 400
, show: 'fade'
, hide: 'fade'
});
$dialog.dialog("option", "buttons", {
"Submit": function () {
var dlg = $(this);
if (IsValidUserName() && $('#frmModalPopup').validate().form()) {
$.ajax({
url: $url,
type: 'POST',
data: $(target).serialize(),
success: function (response) {
var cid = $(response).attr('id');
if (cid != null && cid != undefined) {
$(response).fadeIn('slow').appendTo(id);
$(window).scrollTop($('#' + cid).offset().top);
}

dlg.dialog('close');
dlg.empty();
},
error: function (xhr) {
alertMessage("EmailId is already in use!");
$.validator.unobtrusive.parse('#frmModalPopup');
}
});
}
},
"Cancel": function () {
$(this).dialog('close');
$(this).empty();
}
});

$dialog.dialog('open');
};


But when I do multiple clicks on Submit button at time (more than once) then form is submitted more than once and I got duplicate data submission information. So could you please tell me how to disable double click or more than once click on button Submit.







jquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 '13 at 11:48









Valamas

14.2k2290161




14.2k2290161










asked Mar 21 '13 at 11:47









Arun SinghArun Singh

108616




108616













  • all you had were .net and mvc tags. No jquery tag at all!

    – Valamas
    Mar 21 '13 at 11:48











  • How does stop prevent the submit firing twice?

    – Liam
    Mar 21 '13 at 11:53



















  • all you had were .net and mvc tags. No jquery tag at all!

    – Valamas
    Mar 21 '13 at 11:48











  • How does stop prevent the submit firing twice?

    – Liam
    Mar 21 '13 at 11:53

















all you had were .net and mvc tags. No jquery tag at all!

– Valamas
Mar 21 '13 at 11:48





all you had were .net and mvc tags. No jquery tag at all!

– Valamas
Mar 21 '13 at 11:48













How does stop prevent the submit firing twice?

– Liam
Mar 21 '13 at 11:53





How does stop prevent the submit firing twice?

– Liam
Mar 21 '13 at 11:53












3 Answers
3






active

oldest

votes


















3














Disable the dialog on first submit, check if it is disabled before proceeding, return if already disabled.



"Submit": function () {
if ($(this).hasClass("disabled"))
return;

$(this).addClass("disabled");

// continue;
}


Edit: You can use this approach to add some additional user interface responsiveness, by adding a "Working..." or some other message when you disable it



$(this).addClass("disabled");
$dialog.append("Working...");





share|improve this answer































    0














    jquery ui has nice function named isOpen().
    If dialog is closed but we can see it to prevent next click we can use function isOpen():



    "Submit": function () {
    if( $(this).dialog("isOpen") ){
    YOUR CODE
    } else {
    return false;
    }
    $(this).dialog("close");
    }





    share|improve this answer































      0














      I need to disable the button for avoid double click but I need the button came back enabled after and async form submitted.



      For this I use a window variable, it's not elegant but functional:



      function openDialog() {
      window.clickOk = false;
      $("#divAnagrafica").dialog({
      ......
      buttons: [
      {
      text: "Ok",
      click: function () {
      if (window.clickOk === true) {
      return;
      }
      window.clickOk = true;
      $("#myForm").submit();
      }
      },





      share|improve this answer
























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15546653%2fhow-can-i-disable-double-click-on-jquery-modal-dialog-button%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        3














        Disable the dialog on first submit, check if it is disabled before proceeding, return if already disabled.



        "Submit": function () {
        if ($(this).hasClass("disabled"))
        return;

        $(this).addClass("disabled");

        // continue;
        }


        Edit: You can use this approach to add some additional user interface responsiveness, by adding a "Working..." or some other message when you disable it



        $(this).addClass("disabled");
        $dialog.append("Working...");





        share|improve this answer




























          3














          Disable the dialog on first submit, check if it is disabled before proceeding, return if already disabled.



          "Submit": function () {
          if ($(this).hasClass("disabled"))
          return;

          $(this).addClass("disabled");

          // continue;
          }


          Edit: You can use this approach to add some additional user interface responsiveness, by adding a "Working..." or some other message when you disable it



          $(this).addClass("disabled");
          $dialog.append("Working...");





          share|improve this answer


























            3












            3








            3







            Disable the dialog on first submit, check if it is disabled before proceeding, return if already disabled.



            "Submit": function () {
            if ($(this).hasClass("disabled"))
            return;

            $(this).addClass("disabled");

            // continue;
            }


            Edit: You can use this approach to add some additional user interface responsiveness, by adding a "Working..." or some other message when you disable it



            $(this).addClass("disabled");
            $dialog.append("Working...");





            share|improve this answer













            Disable the dialog on first submit, check if it is disabled before proceeding, return if already disabled.



            "Submit": function () {
            if ($(this).hasClass("disabled"))
            return;

            $(this).addClass("disabled");

            // continue;
            }


            Edit: You can use this approach to add some additional user interface responsiveness, by adding a "Working..." or some other message when you disable it



            $(this).addClass("disabled");
            $dialog.append("Working...");






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 21 '13 at 11:52









            cernunnoscernunnos

            2,56311417




            2,56311417

























                0














                jquery ui has nice function named isOpen().
                If dialog is closed but we can see it to prevent next click we can use function isOpen():



                "Submit": function () {
                if( $(this).dialog("isOpen") ){
                YOUR CODE
                } else {
                return false;
                }
                $(this).dialog("close");
                }





                share|improve this answer




























                  0














                  jquery ui has nice function named isOpen().
                  If dialog is closed but we can see it to prevent next click we can use function isOpen():



                  "Submit": function () {
                  if( $(this).dialog("isOpen") ){
                  YOUR CODE
                  } else {
                  return false;
                  }
                  $(this).dialog("close");
                  }





                  share|improve this answer


























                    0












                    0








                    0







                    jquery ui has nice function named isOpen().
                    If dialog is closed but we can see it to prevent next click we can use function isOpen():



                    "Submit": function () {
                    if( $(this).dialog("isOpen") ){
                    YOUR CODE
                    } else {
                    return false;
                    }
                    $(this).dialog("close");
                    }





                    share|improve this answer













                    jquery ui has nice function named isOpen().
                    If dialog is closed but we can see it to prevent next click we can use function isOpen():



                    "Submit": function () {
                    if( $(this).dialog("isOpen") ){
                    YOUR CODE
                    } else {
                    return false;
                    }
                    $(this).dialog("close");
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 23 '14 at 9:13









                    Volodymyr YasinskyiVolodymyr Yasinskyi

                    726




                    726























                        0














                        I need to disable the button for avoid double click but I need the button came back enabled after and async form submitted.



                        For this I use a window variable, it's not elegant but functional:



                        function openDialog() {
                        window.clickOk = false;
                        $("#divAnagrafica").dialog({
                        ......
                        buttons: [
                        {
                        text: "Ok",
                        click: function () {
                        if (window.clickOk === true) {
                        return;
                        }
                        window.clickOk = true;
                        $("#myForm").submit();
                        }
                        },





                        share|improve this answer




























                          0














                          I need to disable the button for avoid double click but I need the button came back enabled after and async form submitted.



                          For this I use a window variable, it's not elegant but functional:



                          function openDialog() {
                          window.clickOk = false;
                          $("#divAnagrafica").dialog({
                          ......
                          buttons: [
                          {
                          text: "Ok",
                          click: function () {
                          if (window.clickOk === true) {
                          return;
                          }
                          window.clickOk = true;
                          $("#myForm").submit();
                          }
                          },





                          share|improve this answer


























                            0












                            0








                            0







                            I need to disable the button for avoid double click but I need the button came back enabled after and async form submitted.



                            For this I use a window variable, it's not elegant but functional:



                            function openDialog() {
                            window.clickOk = false;
                            $("#divAnagrafica").dialog({
                            ......
                            buttons: [
                            {
                            text: "Ok",
                            click: function () {
                            if (window.clickOk === true) {
                            return;
                            }
                            window.clickOk = true;
                            $("#myForm").submit();
                            }
                            },





                            share|improve this answer













                            I need to disable the button for avoid double click but I need the button came back enabled after and async form submitted.



                            For this I use a window variable, it's not elegant but functional:



                            function openDialog() {
                            window.clickOk = false;
                            $("#divAnagrafica").dialog({
                            ......
                            buttons: [
                            {
                            text: "Ok",
                            click: function () {
                            if (window.clickOk === true) {
                            return;
                            }
                            window.clickOk = true;
                            $("#myForm").submit();
                            }
                            },






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 23 '18 at 9:36









                            iLoveCodeiLoveCode

                            417




                            417






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15546653%2fhow-can-i-disable-double-click-on-jquery-modal-dialog-button%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                                Alcedinidae

                                Can an atomic nucleus contain both particles and antiparticles? [duplicate]