2

I am a total noob with jQuery and js and I am certain there is a more elegant solution then what I have come up with - but this is what I have so far and I'm stumped.

I have a form that takes a long time to submit for various reasons - I am using validationEngine to validate the form fields inline which works great. I then needed to add a pop-up div to tell the visitor to please be patient why the application performs the requested search.

My original solution worked great accept that the pop-up div showed when the visitor clicked submit regardless if the form was completely filled out or not - it the form is completely filled out everything works as expected - if they miss a field validationEngine shows the missing field notification and my pop-up div still shows up but obviously the form does not submit. That happens with this code:

jQuery(document).ready(function(){
    jQuery("#approvalForm").validationEngine('attach');
});

    $(document).ready(function() {
        $('#approvalForm').submit(function() {
            $('#progress').show();
            });
        });

So after some research I made some modifications that resulted in this code:

    jQuery(document).ready(function(){
    jQuery("#approvalForm").validationEngine('attach', {
        onValidationComplete: function(form, status){
        if (status == true) {
            $('#approvalForm').submit(function() {
                    $('#progress').show();
                });
        }
             }
     });
});

And now everything works correctly except that you have to click the submit button twice and when you do the pop-up div comes up but the form does not submit.

2
  • Do you happen to have the current version online somewhere? Also — be aware that, if you attach a submit handler to a form, that you have to manually prevent the default event (submitting the form), e.g. by returning false at the end of your handler function. [And I had a quick look at the source of the plugin (which I don't know) and it looked like (don't quote me) that they would be passing first the status and then the form (in version 2.0 beta)?] Commented Mar 5, 2011 at 20:51
  • The current version is here haloadvance.com/testsite - but its the form after you submit this one. - I can provide the complete code for the page if that helps. Commented Mar 5, 2011 at 22:06

4 Answers 4

2
$('#form1').validationEngine('attach', {
    onValidationComplete: function(form, status){
        if (status == true) {                   
            startProgressBar();
            form.validationEngine('detach');
            form.submit();

        }
    }           
});
Sign up to request clarification or add additional context in comments.

Comments

0
jQuery("#approvalForm").validationEngine('attach', {
    onValidationComplete: function(form, status){
    if (status == true) {
        $('#progress').show();
        $('#approvalForm').trigger('submit');
    }else{
        $('#progress').hide();
    }
}

But I think if you want to display loading popup,
you must use jQuery.ajax

It have beforeSend function that will run before browser send request.

Comments

0

onValidationComplete stops the form submitting, and lets you handle things yourself. In this case, all you want to do is display the loading popup when the validation passes. So instead, what you could do is hook into the result of the validation, and if it has passed show the loading popup. The form submission would then activate as normal.

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#approvalForm").validationEngine('attach');
    jQuery("#approvalForm").bind("jqv.form.result", function(event, errorFound) {
        if(!errorFound) $('#progress').show();
    })
});
</script>

Comments

0

you need

$('#approvalForm').validationEngine('attach', {
    onValidationComplete: function(form, status){
        if (status) {                   
            startProgressBar();
            YouFunctionPreLoad();
            return true;
            //form.submit();
        }
    }           
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.