Keep p:dialog open when a validation error occurs after submit

后端 未结 6 607
我在风中等你
我在风中等你 2020-11-22 15:22

Minimal example dialog:

 
  

        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 15:50

    I believe this is the cleanest solution. Doing this you don't need to change your buttons code. This solution overrides the hide function prototype.

    $(document).ready(function() {
        PrimeFaces.widget.Dialog.prototype.originalHide = PrimeFaces.widget.Dialog.prototype.hide; // keep a reference to the original hide()
        PrimeFaces.widget.Dialog.prototype.hide = function() {
            var ajaxResponseArgs = arguments.callee.caller.arguments[2]; // accesses oncomplete arguments
            if (ajaxResponseArgs && ajaxResponseArgs.validationFailed) {
                return;  // on validation error, prevent closing
            }
            this.originalHide();
        };
    });
    

    This way, you can keep your code like:

    
    

提交回复
热议问题