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
BedrockMission!

Learn More

View all

Sign in to view all badges

Dynamic Default Value for Date/Time Field

Avatar

Avatar
Level 1
dayvidp
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
dayvidp
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
View profile
dayvidp
Level 1

08-01-2019

I am creating a form for applicants to a selective program.  To be competitive for selection, applicants need to have worked in our industry for 3-7 years after graduating with their bachelor's degrees.  I want the user-entered graduation date field (Date/Time field type) to default to a value that is roughly 5 years (1825 days) before the date in which they are entering the data, and I want the user to see an empty field until they select it to enter their graduation date.  Initially, I created a static default value in the "Value" tab, but that value is displayed when the form is generated, which I don't want.  Then I tried adding the following code to the "enter" event of my graduation date field, but it also didn't help:

form1.#subform[0].ServiceDate::enter - (JavaScript, client)

if (this.rawValue == null){

  this.rawValue = (d.getDate() - 2190);

}

I appreciate any recommendations.  Thanks!

Accepted Solutions (0)

Answers (5)

Answers (5)

Avatar

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,077 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,077 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile
Magus069
MVP

10-01-2019

Mhmm, I don't know why it is behaving like this... maybe change the data pattern to yyyy-mm-dd, or change the pattern in util.printd to match the data pattern of the field... otherwise I don't know, maybe if I could see the form I could test things out

Avatar

Avatar
Level 1
dayvidp
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
dayvidp
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
View profile
dayvidp
Level 1

09-01-2019

I tried moving it to the initialize event, but the dropdown calendar still started in 2019, even though the date displayed in the field was 9 Jan 14.  If I manually enter 01/09/14 in the field, then the dropdown calendar begins with 9 Jan 2014.

Avatar

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,077 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,077 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile
Magus069
MVP

09-01-2019

In this case, it should be set before entering the field... that means the field would not be blank before entering the field.

If this is what you want, I suggest you put the script within the initialize event.

Avatar

Avatar
Level 1
dayvidp
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
dayvidp
Level 1

Likes

0 likes

Total Posts

5 posts

Correct Reply

0 solutions
View profile
dayvidp
Level 1

09-01-2019

That helps a lot!  Strangely, though, even after the new dynamic default value appears upon entering the field, the initial date in the calendar dropdown where the user can select a date is still in 2019.  Any suggestions for how to change that to match what's in the field?

Avatar

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,077 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,077 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile
Magus069
MVP

08-01-2019

Hi there,

I suggest you use this approach instead, using the util.printd();

First put this in the enter event, if you want it to stay default when no value is entered you can put it in the exit event as well.

I hope this will help.