取消在p:accordionPanel中关闭标签页 [英] cancel tab closing in p:accordionPanel

查看:129
本文介绍了取消在p:accordionPanel中关闭标签页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ap:accordionPanel,面板的每个标签内都有一些用户可以操纵的信息,我需要做的是,如果用户关闭该标签,则显示一个确认对话框(在关闭该标签之前)诸如您确定要关闭选项卡吗?如果您所做的更改将丢失。这是我尝试过的

I have a p:accordionPanel and inside of each tab of the panel there is some info that the user can manipulate, what i need to do is if the user close the tab show a confirm dialog (before the tab get closed) whit something like "are you sure you wanna close the tab? if you do your changes will be lost". here is what i tried

<p:ajax event="tabClose" onstart="return myFunction()" 
listener" {myBean.myMethod}" process="@this" />







function myFunction() {
    var answer = confirm("are you sure you wanna close the tab? if you do your changes will be lost");
    if(answer){
        //some logic 
        return true;
    }else{
        //some logic
        return false;
    }
}

问题是,如果我在确认时选择取消对话框中的标签仍然会关闭。 onStart = return false 是否应该取消制表符关闭?

The problem is that if i choose cancel on the confirm dialog the tab get close anyway. Shouldn't the tab closing be canceled by the onStart="return false"? is there a way to achieve what i'm trying to do?

推荐答案

最后我解决了我的问题,显然是 onStart = return false 不会阻止选项卡更改其状态,而是 onTabChange 属性p:accordionPanel 确实存在,唯一的问题是,由于某些原因,关闭选项卡时手风琴的 onTabchange 事件无法执行只是在打开选项卡时,所以我必须重写primefaces的acordionPanel取消选择功能才能调用onTabChange事件

Finally I solved my problem, apparently the onStart="return false" does not prevent the tab from change its statatus but the onTabChange attribute of the p:accordionPanel does, the only problem is that for some reason the onTabchange event of the accordion don't get execute when the tab is been closed just when the tab is been opened so i have to override the acordionPanel unselect function of primefaces to call the onTabChange event

PrimeFaces.widget.AccordionPanel.prototype.unselect = (function(index) {
  var cached_function = PrimeFaces.widget.AccordionPanel.prototype.unselect;

  return function() {
    var panel = this.panels.eq(index);

    if(this.cfg.onTabChange) {
        var result = this.cfg.onTabChange.call(this, panel);
        if(result === false)
            return false;
    }

    var result = cached_function.apply(this, arguments); 

    return result;
  };
})();

然后我只需要放置 myFunction(); 在手风琴面板的onTabChange事件上( onTabChange = return myFunction() )即可。

then i only had to placed myFunction(); on the onTabChange event of the accordiong panel (onTabChange="return myFunction()")and it works.

这篇关于取消在p:accordionPanel中关闭标签页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆