I was wondering if there was a way to make the beginning of each cell start with some dynamic variable (this.code in this case)? This is my custom editor
class CustomEditor extends Handsontable.editors.TextEditor {
constructor(props) {
super(props);
}
setValue(newValue){
const cellVal = this.cellProperties.instance.getDataAtCell(this.row, this.col);
this.TEXTAREA.value = (cellVal && cellVal.match(new RegExp(`^${this.code}.*`))) ?
newValue :
this.code;
}
createElements() {
super.createElements();
this.TEXTAREA = document.createElement('input');
this.TEXTAREA.className = 'handsontableInput';
this.textareaStyle = this.TEXTAREA.style;
Handsontable.dom.empty(this.TEXTAREA_PARENT);
this.TEXTAREA_PARENT.appendChild(this.TEXTAREA);
}
}
and using the wrapper for react, I pass the code into the editor on every render call like this
render() {
CustomEditor.prototype.code = this.props.code;
...
}
and it currently adds the code on double click of the empty cell, and preserves it’s value if it starts with the code already, very nice. I wish to make it so that the code is not able to be deleted, so one can only add to the code. Is this possible?