Cancel Event p:tab

UI Components for JSF
Post Reply
csyperski
Posts: 103
Joined: 16 Apr 2010, 14:36

10 Mar 2011, 19:06

I am attempting to implement functionality on a p:tabView that would alert the user if they are trying to change tabs without saving, if they modified any of the fields. I am trying to use the onTabChange callback, but it doesn't seems that I can cancel the event, is this true. Is there anyway to abort the change of the tabs?

I feel like I am close, but the problem is that my dialog "confirmNavigation" shows up for a second, then is closed by the navigation to the new tab, because it doesn't block. So I was hoping to cancel the event then do the naivgation from the dialog, is this possible?

Here is what I have:

Code: Select all

<p:tabView onTabShow="bindForChange();" onTabChange="handleTabChange(event, ui);" effect="height" cache="false" collapsible="true" dynamic="true"  >

Code: Select all

<script type="text/javascript">
                dataChanged = 0;

                function bindForChange()
                {
                     jQuery('input,checkbox,textarea,radio,select').bind('change',function(event) {dataChanged = 1});
                     jQuery(':reset,:submit').bind('click',function(event) { dataChanged = 0 });
                }

                function fireDataChanged()
                {
                    dataChanged = 1;
                }

                function handleTabChange(event, ui)
                {
                    if ( dataChanged )
                    {
                        confirmNavigation.show();
                        //abort and let my dialog above handle things from here!!!
                        return false;
                    }
                }


            </script>
I am using tomcat 6 and PF 2.2.1

Thanks

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 61 guests