How to make date field reflect current year if user enters only m/d?

perris94323930

01-10-2015

I have a date field that needs to act like an Excel cell; e.g., if user enters 7/21, the date displays the current year as well(7/21/15).  I can't figure out how to use edit patterns to do this (and I'm not very familiar with FormCalc or JS).  Thank you!

Accepted Solutions (0)

Answers (1)

Answers (1)

_Bruce_Robertson

MVP

01-10-2015

Hi,

Try this code in the exit event of the date field.

if (this.formattedValue == this.rawValue) {

  var parts = this.rawValue.split('/');

  if (parts.length == 2) {

  var d = new Date()

  d.setMonth(parts[0]-1, parts[1]);

  this.rawValue = util.printd('yyyy-mm-dd', d);

  }

}

The this.formattedValue == this.rawValue part is a way of testing for an invalid date, if it was value was valid then the rawValue would be in the data format which defaults to yyyy-mm-dd, if its not valid then the invalid value gets copied across. Then we split the value into two and update the current date with the day and month and update the field.

Bruce