Ext


Go Back   Ext JS Forums > Ext JS Premium Forums > Ext: Premium Help

Reply
 
Thread Tools
  #1  
Old 11-04-2009, 03:37 AM
teqneers's Avatar
teqneers teqneers is offline
Ext JS Premium Member
 
Join Date: Nov 2008
Posts: 14
teqneers is on a distinguished road
Default cancel CheckItem actions

Hi,

in our application, we have a menu with some CheckItems, e.g. a language selector to switch between different application languages. Also we work a lot with EditorGrids. I somebody click a CheckItem, we allways check, if the Grid is dirty to show a message before going on to avoid loss of not saved changes.

My problem is, that i can simply cancel the event but i cannot cancel the changes in the menu itself. If i work also with the beforecheckchange event in the checkitem itself, i can cancel selecting the item, but the other item which was selected before is already unselected at this time.

e.g.
we have two different languages, german and english, and english is marked as active. If i now would like to switch to german and the grid is dirty, the users gets a message if he really want to change and loss his data. At this time, i cancel the change and german wasn't selected. But english is now no more selected?

Is their a way to recover the old selection?
Reply With Quote
  #2  
Old 11-04-2009, 10:42 AM
Condor's Avatar
Condor Condor is online now
Ext JS - Community Support Team
 
Join Date: Mar 2007
Location: The Netherlands
Posts: 14,250
Condor is on a distinguished road
Default

I think you should be able to use the beforecheckchange event to return false, but you need to register the handler in the listeners config option and not using on() or addListener().
__________________
Condor
Reply With Quote
  #3  
Old 11-04-2009, 01:02 PM
teqneers's Avatar
teqneers teqneers is offline
Ext JS Premium Member
 
Join Date: Nov 2008
Posts: 14
teqneers is on a distinguished road
Default

i did so, but if i will return false, the Checkitem which was marked as checked before is also unchecked then. So i will end up in a list without any item checked.
Reply With Quote
  #4  
Old 11-04-2009, 02:46 PM
Condor's Avatar
Condor Condor is online now
Ext JS - Community Support Team
 
Join Date: Mar 2007
Location: The Netherlands
Posts: 14,250
Condor is on a distinguished road
Default

Well, this worked for me:
var allow;
new Ext.Button({
    text: 'Click me',
    menu: {
        defaults: {
            group: 'group',
            checked: false,
            listeners: {
                beforecheckchange: function(){
                    var cur = allow;
                    allow = false;
                    return cur;
                }
            }
        },
        items: [{
            text: 'Item 1',
            checked: true
        },{
            text: 'Item 2'
        },{
            text: 'Item 3'
        }]
    },
    renderTo: Ext.getBody()
});
__________________
Condor
Reply With Quote
  #5  
Old 11-04-2009, 03:33 PM
teqneers's Avatar
teqneers teqneers is offline
Ext JS Premium Member
 
Join Date: Nov 2008
Posts: 14
teqneers is on a distinguished road
Default

this couldn't be the right way. the beforecheckchange is also triggered on rendering the menu the first time??? how should i find out, if this is a user click or a menu open event?
Reply With Quote
  #6  
Old 11-05-2009, 03:48 AM
Condor's Avatar
Condor Condor is online now
Ext JS - Community Support Team
 
Join Date: Mar 2007
Location: The Netherlands
Posts: 14,250
Condor is on a distinguished road
Default

IMHO that's a small bug in CheckItem, which you can fix with:
Ext.override(Ext.menu.CheckItem, {
    setChecked : function(state, suppressEvent){
        if(this.checked != state && (suppressEvent === true || this.fireEvent("beforecheckchange", this, state) !== false)){
            if(this.container){
                this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
            }
            this.checked = state;
            if(suppressEvent !== true){
                this.fireEvent("checkchange", this, state);
            }
        }
    }
});
__________________
Condor
Reply With Quote
  #7  
Old 11-05-2009, 05:13 AM
teqneers's Avatar
teqneers teqneers is offline
Ext JS Premium Member
 
Join Date: Nov 2008
Posts: 14
teqneers is on a distinguished road
Default

Many thanks. Now it's working fine.
Reply With Quote
Reply

Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT -5. The time now is 03:32 PM.

© 2006-2009 Ext, LLC
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.