I have a form that is being submitted using an sj:submit tag from the struts2-jquery plugin. The submit button is setup with a validateFunction and an onAfterValidationTopic. I'm trying to block the form using the jquery BlockUI when a user saves this form via the sj:submit. The problem is that the BlockUI does not turn on until after validation has completed. Since this form is quite extensive and validation takes a second, this gap in time is extremely noticeable to a user.
BlockUI is being invoked via a javascript method added to the button's onClick parameter. I have set the fadeIn to 0 so it should be executing synchronously.
Through breakpointing, I have determined that the BlockUI is called before any of the struts2-jquery validation methods, but the block is still not appearing until after the form is validated and it's either submitted or validation warnings are flagged.
My order of operations should be to block the UI via the onClick parameter, have the struts2-jquery plugin submit the form for validation, then fire my AfterValidationTopic which will unblock the UI if the validation was unsuccessful. All those steps are happening in the correct order, except that I don't see the UI being blocked. I'm at a loss as to why this would be the case. I went so far as to try and add a $.blockUI call in the jquery.struts2.js file into the $.elem.click function with the same results. BlockUI is being invoked, but I'm not seeing it.
Here's my JSP:
<sj:submit
button="true"
type="button"
id="save_button"
cssClass="btn bg-cobalt-300"
buttonIcon="icon-floppy-disk"
label="Save"
validate="true"
formIds="my_form"
onAfterValidationTopics="postValidation"
validateFunction="bootstrapValidation"
value="%{getText('global.save')}"
onClick="loadingMaskSave();"
/>
and JS code:
function loadingMaskSave() {
$.blockUI({
fadeIn: 0
});
}
$.subscribe('postValidation', function (event,data) {
if(event.originalEvent.formvalidate == false) {
$.unblockUI();
}
});