Posted 13 March 2019, 10:56 am EST
Is there any way I can limit how many characters the user can input to a single cell?
Forums Home / Spread / DataViewsJS
Posted by: wmeng on 13 March 2019, 10:56 am EST
Posted 13 March 2019, 10:56 am EST
Is there any way I can limit how many characters the user can input to a single cell?
Posted 15 March 2019, 7:23 am EST
Hi,
Please refer to the post about how to limit characters user can input in cell.
https://www.grapecity.com/en/forums/spread-sheets/spread-format-and-cells-pr
Posted 18 March 2019, 3:06 pm EST
The example you refer to is for SpreadJs.sheet, how do I use it in spread.views?
Posted 19 March 2019, 9:28 am EST
In case of Spread.Views we could handle the editing event and then set the max-length attribute on the input element.
Please refer to the following code snippet and attached sample:
dataView.editing.addHandler(function(s,e){
// apply max length
if(e.status == "startEditing"){
var editorContainer = s.container.querySelector('.gc-inline-editor-container[data-column="country"]');
if(!editorContainer){
return;
}
let inp = editorContainer.querySelector('input');
if(!inp){
return;
}
inp.setAttribute('maxlength', '8');
}
// forcing country check
if(e.status == "beforeEndEditing"){
if(e.newItem && e.oldItem && e.oldItem.country != e.newItem.country){
// country changed, check length
if(e.newItem.country.length > 8){
// force validation, restore country or trim input
e.newItem.country = e.oldItem.country;
}
}
}
});
Posted 19 March 2019, 9:29 am EST