How to limit the max characters in the cell?

Posted by: wmeng on 13 March 2019, 1:56 am EST

    • Post Options:
    • Link

    Posted 13 March 2019, 1:56 am EST

    Is there any way I can limit how many characters the user can input to a single cell?

  • Posted 14 March 2019, 10:23 pm 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, 6:06 am EST

    The example you refer to is for SpreadJs.sheet, how do I use it in spread.views?

  • Posted 19 March 2019, 12: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, 12:29 am EST

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels