0

I am customizing a wordpress theme. When the user clicks the submit button it should be disabled.

I was not able to figure out how to do it. Here is the code. Could someone please tell me how to do this.

jQuery('.modal-content').dialog({
                autoOpen: false, 
                title: 'Confirm your Res', 
                resizable: false,
                height: 175,
                width: 300, 
                modal: true, 
                buttons: {
                    Submit: function() {                                    

                        jQuery('form[name="booking-form"]').get(0).submit();
                    }, 
                    Cancel: function() {
                        jQuery(this).dialog("close");

                    }
                }
            });
Tariqulazam
  • 4,535
  • 1
  • 34
  • 42
Steve
  • 1,028
  • 7
  • 25
  • 42

5 Answers5

2

I'm using this code on my website.

$("#dialog-alert").dialog({
    autoOpen: false,
    width: 320,
    modal: true,
    buttons: {
        Submit: function (e) {
            // Disable button
            $(e.target).attr("disabled", true);

            // Write your code here

            // Enable button
            $(e.target).removeAttr("disabled");
        }
    },
});
tano8753
  • 76
  • 2
1
$('.submit').click(function(event) {
 event.preventDefault();
});

or see

Disable submit button on form submit

Community
  • 1
  • 1
Christopher Marshall
  • 10,678
  • 10
  • 55
  • 94
0

This will "disable" the button once the form is submitted:

jQuery('.modal-content').dialog({
            autoOpen: false, 
            title: 'Confirm your Res', 
            resizable: false,
            height: 175,
            width: 300, 
            modal: true, 
            buttons: {
                Submit: function() {                                    
                    jQuery('form[name="booking-form"]').get(0).submit($("form[name='booking-form'] input[type=submit]").attr("disabled", "disabled"));
                }, 
                Cancel: function() {
                    jQuery(this).dialog("close");

                }
            }
        });
Samsquanch
  • 8,866
  • 12
  • 50
  • 89
0

This will disable all the buttons on the popup once the user clicks the OK button.

  $(popupHtml).dialog({
    title: "Add an Absence",
    width: 750,
    height: 300,
    buttons: {
        "Ok": function () {
            $(this).parent().find('button[role=button]').attr('disabled', 'disabled');
}

}

RussGove
  • 322
  • 5
  • 18
0

you can also include the disabled styling to make them look disabled

buttons: {
    "Ok": function () {
        $(this).parent().find('button[role=button]').attr('disabled', 'disabled').addClass('ui-state-disabled');

Alternatively you could create your own class with a background "loading" animation for example.

Thomas Smart
  • 386
  • 3
  • 10