Detect date in newValue on EditCell command

Posted by: lpagliaro on 28 December 2017, 7:03 am EST

  • Posted 28 December 2017, 7:03 am EST

    Hello. I created a command that overrides the default editCell command because we needed to do some auditing over the changes and other stuff. I want to be able to detect when the value entered is a date. For example, if I enter ‘12/10/1900’ in a cell, the newValue parameter is treated as string when set to a cell instead of date (this means that it will be left aligned in the cell). Does SpreadJS provides a helper or something to detect this? Because when using the editCell from SpreadJS the value entered looks to be converted to date somehow.

    
    register(commandManager) {
        commandManager.register('editCell', {
          canUndo: true,
          execute: (context, options, isUndo) => {
            if (isUndo) {
              this.undo(options);
            } else {
              this.do(context, options);
            }
          },
        });
      }
    
    do(context, options) {
    ...
    options.sheet.setValue(options.row, options.col, options.newValue);
    ...
    }
    
    
  • Posted 29 December 2017, 1:04 am EST

    Hello,

    You can use the code as below to check if a date in entered in cell:

    
     activeSheet.bind(GC.Spread.Sheets.Events.EditEnded, function (sender, args) {
                    var date = args.editingText;
                    var isvalidDate = isDate(date);
                    if (isvalidDate == true) {
                        alert("date entered");
                    }
                    date = "";
                });   
              
                function isDate(dateVal) {
                    var d = new Date(dateVal);
                    return d.toString() === 'Invalid Date' ? false : true;
                };
    
    

    Hope it helps.

    Thanks,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels