Using jquery ui dialog to confirm action for form submission

前端 未结 3 1608
挽巷
挽巷 2020-12-15 11:28

I have multiple forms on a page, for each of them I want the user to confirm before form submission. but when the user confirms to submit, how do I let this dialog know whic

相关标签:
3条回答
  • 2020-12-15 11:51

    You can store it in a variable like this:

    var currentForm;
    $("#dialog-confirm").dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                'Confirm submit': function() {
                    currentForm.submit();
                },
                Cancel: function() {
                    $(this).dialog('close');
                }
            }
        });
    $('.allForms').submit(function(){
          currentForm = this;
          $('#dialog-confirm').dialog('open');
          return false;
    });
    

    Since you're just using this and immediately just leaving the page, no real reason to make it any more complicated than that.

    0 讨论(0)
  • 2020-12-15 11:54

    Based on Nick Craver his answer, you can write it this way:

    $('.allForms').submit(function(){
          currentForm = this;
    
          $('#dialog-confirm').dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                'Confirm submit': function() {
                    currentForm.submit();
                },
                Cancel: function() {
                    $(this).dialog('close');
                }
            }
          });
          return false;
    });
    
    0 讨论(0)
  • 2020-12-15 11:56

    Or how about

    $(this.form).submit();
    
    0 讨论(0)
提交回复
热议问题