Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

perris94323930
Level 1
Level 1

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!

1 Reply
_Bruce_Robertson
Level 10
Level 10

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