Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery blockUI not working

I'm trying to use blockUI but although it passes over with no errors, it doesn't work

the code below is all within the $(document).ready() function

$("#btnSaveJob").click(function () {

    if ($("#frmJobDetails").valid()) {
        $("#frmJobDetails").submit();
    }

});

$("#frmJobDetails").submit(function (e) {

    $('#jobDetails').block({
        message: 'Saving, please wait...',
        centerX: true,
        centerY: true,
        css: {
            width: '600px',
            height: '300px',
            border: '3px solid #FF9900',
            backgroundColor: '#000',
            color: '#fff',
            padding: '25px'
        }
    });

    submitNew('job');
    e.preventDefault();

    $('#jobDetails').unblock();
});

edit to add in the submitNew function

function submitNew(submitType) {


// various variables set here

    if (submitType == 'job') {
        PageMethods.SubmitJobForm(propID, dateReceived, 
targetResponse, targetComplete, chargeable, jobTypeID, 
jobTypeText, contractID, contractText, csJobTypeID, 
csJobTypeText, priorityID, priorityText, status, notes, 
fnsuccesscallbackJob, fnerrorcallback);
    }
    else if (submitType == 'instruction') {
        PageMethods.SubmitInstruction(fnsuccesscallbackInstruction,
fnerrorcallback);

    }
    else {

    }

}

have to add this bit in as editor complaining I've added too much code....

like image 422
leddy Avatar asked Nov 29 '25 12:11

leddy


2 Answers

Try this :

<script
    src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript"
    src="https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.66.0-2013.10.09/jquery.blockUI.js">
</script>

<script>
$(document).ready(function() {

        $('#btnSubmit').on('click', function() {

            $('#form').validate({
                errorPlacement : function(error, element) {
                    error.insertBefore(element); // <- the default
                },

                rules : {
                    username : {
                        required : true
                    },
                    password : {
                        required : true,
                    },
                },
                messages : {
                    username : {
                        required : " Username required."
                    },
                    password : {
                        required : " Password required."
                    },
                },

            });
            if($('#form').valid()){
                $.blockUI({ message: 'Just a moment...</h1>' });
            }
        });

    });
</script>
like image 188
Gurkha Avatar answered Dec 02 '25 03:12

Gurkha


In the current way the code is executed in the order:

  • block
  • submit function, async I think
  • unblock

so since the submit function is async the unblock is executed too early and not when the submit process completes.

Try to move the unblock function in the complete/done function of the ajax call.

like image 25
Irvin Dominin Avatar answered Dec 02 '25 01:12

Irvin Dominin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!