EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Stefan B. on June 27, 2014, 03:28:10 AM



Title: How can I show a confirm message before submit form data?
Post by: Stefan B. on June 27, 2014, 03:28:10 AM
How can I show a confirm message before submit form data and if the result of confirm is false to cancel the submit action?
The following code is not working while the $.messager.confirm() working asynchronous.

Code:
	    onSubmit: function(param){ //Fires before submit, return false to prevent submit action.
    if($(this).form('validate') == false) { //validate form data
    $.messager.alert(infoTitleInvalidInput, infoTitleInvalidMsg, "error");
    return false;
    };
   
    $.messager.confirm(infoTitleConfirm, confirmEdit, function(r){
if (r) {  return true;}
    });
return false;
    },


Title: Re: How can I show a confirm message before submit form data?
Post by: stworthy on June 27, 2014, 06:16:00 PM
Please try this:
Code:
$('#ff').form({
onSubmit:function(){
var f = this;
var opts = $.data(this, 'form').options;
if($(this).form('validate') == false){
return false;
}
$.messager.confirm('Confirm','Are you sure?',function(r){
if (r){
var onSubmit = opts.onSubmit;
opts.onSubmit = function(){};
$(f).form('submit');
opts.onSubmit = onSubmit;
}
})
return false;
}
});