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

Avatar

Avatar
Level 1
perris94323930
Level 1

Likes

0 likes

Total Posts

4 posts

Correct reply

0 solutions
View profile

Avatar
Level 1
perris94323930
Level 1

Likes

0 likes

Total Posts

4 posts

Correct reply

0 solutions
View profile
perris94323930
Level 1

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)

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_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