Posted 26 October 2017, 11:11 am EST
Hi,
Is there any way to prevent users from using the undo/redo functionality on a FlexSheet? I don’t want the undo/redo actions to be performed when users type the corresponding keyboard shortcuts.
Thanks,
Holly
Forums Home / Wijmo / General Discussion
Posted by: holly.anderson on 26 October 2017, 11:11 am EST
Posted 26 October 2017, 11:11 am EST
Hi,
Is there any way to prevent users from using the undo/redo functionality on a FlexSheet? I don’t want the undo/redo actions to be performed when users type the corresponding keyboard shortcuts.
Thanks,
Holly
Posted 27 October 2017, 7:51 am EST
Hi Holly,
You need to handle keyDown event and prevent action to be performed for Ctrl+z/y.
~Manish
Posted 30 October 2017, 10:01 am EST
Hi Manish,
Would this let me prevent undo/redo on the FlexSheet but allow those actions when they pertain to other elements on the page? If so, could you provide a little more detail on how to do that?
Thanks,
Holly
Posted 31 October 2017, 2:57 am EST
Hi Holly,
Yes, you can limit this to FlexSheet only by handling keyDown event for FlexSheet hostElement. Please refer to the following code snippet for the same:
flexSheet.hostElement.addEventListener("keydown",function(e){
// code to prevent undo/redo
});
Posted 2 November 2017, 11:42 am EST
Hi Manish,
I’m still having trouble with this. I’ve done the following, but the undo/redo actions are still being performed.
flexSheet.hostElement.addEventListener("keydown", function (e) {
if (e.ctrlKey && (e.key === 'z' || e.key === 'y')) {
e.preventDefault();
e.stopPropagation();
return
}
});
Holly
Posted 3 November 2017, 2:58 am EST
Sorry Holly,
We need to capture the keyDown event for this. Please refer to the updated code snippet:
flex.hostElement.addEventListener("keydown", function (e) {
if (e.ctrlKey && (e.key === 'z' || e.key === 'y')) {
e.preventDefault();
e.stopPropagation();
}
},true);
~Manish
Posted 3 November 2017, 7:48 am EST
Hi Manish,
This still isn’t working for me. Please see the attached sample and follow these steps:
Results: The value in the first Name cell reverts to ‘Item1’.
I think this might be a problem with version 5.20172.359. If I use 5.20172.334, then the undo/redo is prevented as expected.
Holly
Posted 6 November 2017, 5:23 am EST
Hi Holly,
We are sorry for the inconvenience. We are able to replicate the issue at our end with 5.20172.359 build and it seems a bug. Hence, this issue has been forwarded to the concerned team for further investigation with tracking id 295414.
We will let you know as we get an update in on this.
~Manish
Posted 6 November 2017, 7:34 am EST
Hi Holly,
Please use the following workaround in the meantime while this is getting fixed by development team:
sheet.addEventListener(document.body,"keydown", function (e) {
if (e.ctrlKey && (e.key === 'z' || e.key === 'y') && wijmo.contains(sheet.hostElement, e.target) ) {
e.preventDefault();
e.stopPropagation();
}
},true);
~Manish
Posted 15 December 2017, 9:06 am EST
Any update on when this will be fixed?
Posted 18 December 2017, 7:30 am EST
Hi Holly,
This issue logged as enhancement and it will be included in the future releases but we can not provide any estimation.
Hence, please use the provided workaround and let me know if you any query on this.
~Manish
Posted 28 February 2018, 8:22 am EST
Hi manish,
I am using wijmo 5 with angular 2.I have same query. Preventdefault or stoppropagation is not working in flexsheet.
I used your code:
sheet.addEventListener(document.body,“keydown”, function (e) {
if (e.ctrlKey && (e.key === ‘z’ || e.key === ‘y’) && wijmo.contains(sheet.hostElement, e.target) ) {
e.preventDefault();
e.stopPropagation();
}
},true);
but these two functions are not preventing my function.Is there any solution
Actually i want to stop delete event when I click on delete key.I am getting the event when delete key is pressed,but the two functions are not stopping it from deleting the data.
With regards
Dharna Bakshi
Posted 1 March 2018, 10:47 am EST
We are sorry Dharna. At this time we do not have a solution for the same. I will however enquire with the Dev Team and let you know if we have any other possible workarounds.
Posted 1 March 2018, 11:16 am EST
Hi Dharna,
Please try following code:
sheet.hostElement.addEventListener("keydown", function (e) {
console.log(e.keyCode)
if (e.ctrlKey) {
if (e.keyCode === 90 || e.keyCode === 89) { // Z/Y
e.preventDefault();
e.stopImmediatePropagation();
}
}
}, true);
This should work fine.
Note that you have to call stopImmediatePropagation. Calling preventDefault should be enough, but the sheet code does not check for defaultPrevented, so you really have to stop the event immediately like this.
~Manish