|
|||||||
![]() |
|
|
Thread Tools |
|
#1
|
||||
|
||||
|
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? |
|
#2
|
||||
|
||||
|
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
|
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
||||
|
||||
|
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
|
|
#5
|
||||
|
||||
|
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?
|
|
#6
|
||||
|
||||
|
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
|
|
#7
|
||||
|
||||
|
Many thanks. Now it's working fine.
|
![]() |
| Thread Tools | |
|
|