Expand my Community achievements bar.

SOLVED

Setting "default" of a date field equal to another date field

Avatar

Level 4

Hello,

Date field 1 is user entered. 

Date field 2 I want to be user entered, UNLESS the first date field is entered.  If the first date is entered as 10/2/2012, then I'd want date 2 to have the default 10/2/2012.  If possible, I'd like to let the user override. 

I've been playing around but I'm not sure which javascript function to use.  I'm really familiar with rawvalue but not for whatever the value would be in a date field.  Any suggestions?

Thanks so much!

1 Accepted Solution

Avatar

Correct answer by
Level 10

You could do something like:

//on exit event of first date field

if (DateTimeField2.isNull) {

    DateTimeField2.rawValue = this.rawValue;

}

Depends on how you want to treat the second date field. In the sample above I've specified to only set the value of the second date field if it's empty. That way if someone has set the second date field and goes back and changes the first date field nothing will happen.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

You could do something like:

//on exit event of first date field

if (DateTimeField2.isNull) {

    DateTimeField2.rawValue = this.rawValue;

}

Depends on how you want to treat the second date field. In the sample above I've specified to only set the value of the second date field if it's empty. That way if someone has set the second date field and goes back and changes the first date field nothing will happen.

Avatar

Level 4

Thanks for the idea. Can I make DateTimeField2 calculated only when DateTimeField1 has been entered? Otherwise, I'd like the users to be able to choose their own DateTimeField2 value.

Avatar

Level 10

That's what that script does essentially...when the person exits the first date field the second date field is set to the same value unless the second date field already has a value. The filler can still set the value of the second date field.

If you are not worried about overwriting a value in the second date field you can remove the if statement and just use DateTimeField2.rawValue = this.rawValue;