Click here to Skip to main content
15,882,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
iam useing http://formvalidation.io to validate my form in asp.net and it work fine, i am trying to use blockui http://malsup.com/jquery/block/ to block the page on long process but it fire up when button submit before form validate and keep page blocked. how to validate form first then block page while saving

<script>
    $(document).ready(function () {
        $('#form1').formValidation({
            framework: 'bootstrap',
            icon: {
                valid: 'fa fa-check',
                invalid: 'fa fa-times',
                validating: 'fa fa-refresh'
            },
            fields: {
               <%=txtName.UniqueID %>: {
                row: '.col-md-4',
                    validators: {
                        notEmpty: {
                            message: 'Name is required'
                        },
                    }
                },
             }
        });
    });   

$(function (e) {
        $('#<%= btnSave.ClientID %>').click(function () {

            if ($('#form1').validate()) {
                $('div.msbl').block({
                    message: '<h5><img src="img/loading.gif" />Loading </h5>',
                });
            }
        });
    });
</script>


What I have tried:

i tried blockui with jquery validation and work fine but i want to use it with The best jQuery validation plugin to validate form fields, support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks - FormValidation[^]
Posted
Updated 23-Apr-17 11:36am

1 solution

You can make your form model (blocking) quite easily by placing a transparent div at a Z-index "above" the form, the making everything on the form un-clickable whilst that div is present.

JavaScript
this.blockingObj = document.createElement("DIV");
document.body.appendChild(this.blockingObj);
this.blockingObj.style.background = "transparent";
this.blockingObj.style.zIndex = this.obj.style.zIndex - 1; // Above everything else.
this.blockingObj.style.width = document.documentElement.clientWidth + "px";
this.blockingObj.style.height = document.documentElement.clientHeight + "px";
this.blockingObj.style.position = "relative";
this.blockingObj.style.left = "0px";
this.blockingObj.style.top = "0px";

Of course you need to remove this.blockingObj when you want to re-enable the form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900