-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[7.1.1] Can't set data in a readOnly cell if there is any selection #6214
Comments
I think I've traced it to this particular PR: https://github.com/handsontable/handsontable/pull/6021/files. Specifically, https://github.com/handsontable/handsontable/pull/6021/files#diff-7eb52b366866677666470e019283c8eaR926 and https://github.com/handsontable/handsontable/pull/6021/files#diff-7eb52b366866677666470e019283c8eaR947. I think the issue is that when the selection is on a readOnly cell and you try to update any other cell, then the activeEditor returns the editor of the readOnly cell. I think the bigger issue is that the editor should really be the editor that goes along with the cell thats being updated, not necessarily the active editor. If I have my selection on a DateCell and something calls |
Here's my full monkey patch, for anyone interested. Temporarily overwriting /**
* Monkey patch anything we want on the HoT instance
* @param hot
*/
function monkey(hot) {
const setDataAtRowProp = hot.setDataAtRowProp;
const setDataAtCell = hot.setDataAtCell;
const getActiveEditor = hot.getActiveEditor;
// https://github.com/handsontable/handsontable/issues/6208
hot.setDataAtRowProp = function (row, prop, value, source) {
return safeSetData(setDataAtRowProp, row, prop, value, source)
}
// https://github.com/handsontable/handsontable/issues/6208
hot.setDataAtCell = function (row, column, value, source) {
return safeSetData(setDataAtCell, row, column, value, source)
}
function safeSetData(fn, ...args) {
const editor = hot.getActiveEditor();
let restore = null;
// See if there is an editor in a currently editing state
if (editor && editor.state !== 'STATE_VIRGIN') {
// If there is, then grab the value
restore = editor.getValue();
}
// Because of the Github issue referenced below, we need to
// temporarily kill the getActiveEditor method. This is only
// feasible because we do all of our validation server side.
// Should remove this once the bug is addressed.
// https://github.com/handsontable/handsontable/issues/6214
hot.getActiveEditor = () => null;
// Call the core function to set the data
fn(...args);
// Restore the original method
hot.getActiveEditor = getActiveEditor;
// If there was a value being edited, put it back
if (restore !== null) {
editor.setValue(restore);
}
}
// We do all of our validation server side.
// Also: https://github.com/handsontable/handsontable/issues/6214
hot.validateCell = () => false;
hot.getCellValidator = () => null;
return hot;
}
|
Hey @aarondfrancis Thank you for sharing is an interesting bug and doing the whole investigation! I have simplified the example, even more, https://jsfiddle.net/6hu9v845/ but the bug is still present. Tested with Chrome 76/ Windows 10. |
Awesome, thanks for boiling it down even further! Looking forward to a fix. |
I have the same issue with handsontable v.7.1.1. The patch I use in my code is export function applyActiveEditorMonkeyPatch(hotInstance) {
const activeEditor = hotInstance.getActiveEditor();
activeEditor.autoResize.unObserve = () => {};
} |
Connected with #6246 |
* After CR: if we have read-only cell activeEditor is undefined #6214
@aarondfrancis this bug will be fixed in The new version will be released next week. Demo: Environment |
Thanks @aninde! |
That was an interesting bug but I'm glad it is gone ;D Aaron - we've just released a fresh new version. Enjoy |
@kukchanka please update to |
Awesome, thanks yall! |
Description
You should be able to set data in a readOnly cell when any cell is selected, but you can't. If a cell is selected, HoT appears to try to validate something and then errors out with
Cannot read property 'removeEventListener' of undefined
Steps to reproduce
Demo
https://jsfiddle.net/dgh4f6wp/3/
Your environment
The text was updated successfully, but these errors were encountered: