Sunday, March 11, 2012

TabContainer: prevent user from changing current tab

Ok this was an infinite loop...

Here is the code I use now. It launch a confirmation if the user typed something in the current form (tab) depending on my bKeyPressActivated var (defined in a function elsewhere).
(I know we shouldn't care about this as it does not postback, but the confirm before tab changed is required by the business...)

var flag = false;var prevTabIndex = 0;function ActiveTabChanged(sender, args){ if(flag) {flag = false; return;} if(bKeyPressActivated) { if(!confirm('Change tab without saving?')) { flag = true; sender.set_activeTabIndex(prevTabIndex); } else { prevTabIndex = sender.get_activeTabIndex(); bKeyPressActivated = false; } } else { prevTabIndex = sender.get_activeTabIndex(); } }

No comments:

Post a Comment