EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Opan Mustopah on February 08, 2015, 08:15:06 AM



Title: event when failed submit a form
Post by: Opan Mustopah on February 08, 2015, 08:15:06 AM
hello again,

is there a way to make a form have a default event for handling when failed submitting?

as far as i can see in documentatio, there is just onSubmit event.

how to make form plugin achieve this feature?

many thanks for the answer.


Title: Re: event when failed submit a form
Post by: jjosotoro on March 04, 2015, 08:51:54 AM
Hello

As far I undestand you want to know if there was no answer from server after submiting a form. If thats the case the onSubmit can validate if there was no answer, an error or success.

1. create a function to submit when click on button.
2. check for the answers of the onSubmit.

Code:
function saveProcess(){
    $('#fm').form('submit',{
        url: 'SaveProcess.php',
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){ // the url must return an answer
    if (result == '') { // if no answer (submit failed)
                $.messager.show({
                    title: 'Error',
                    msg: 'No answer from server'
                });
     } else if (result.replace(/\W/g,'') !== 'OK'){ //if answer is not OK ("error" you can set your own answer)
                $.messager.show({
                    title: 'Error',
                    msg: result,
width:'650',
height:'800',
style:{
right:'',
bottom:''
}
                });
              } else { //the answer is OK.

              $.messager.show({
                title: 'Success',
                msg: 'Process saved',
style:{
right:'',
bottom:''
}
               });

            }
        }
    });
};


I'm not sure if this is what you're asking, but is a way to validate the submiting of a form.

regards