Expand my Community achievements bar.

SOLVED

Date field changing value

Avatar

Level 2

This form has made a lot of progress since I started working on it, and many thanks to those who have helped. It's doing pretty well, but a couple of fields are getting a value change with the btnSubmit script runs.

The Date Requested field gets reset to the current date, and a small "+" in a black box appears on the field when that happens. Something similar happens in the Email column of the User Information table. I thought I'd ask if anyone can tell why that's happening.

https://acrobat.com/#d=ssxYGPIR*p9K62slHxNp3Q

1 Accepted Solution

Avatar

Correct answer by
Level 10

On line 61 of the script on btnSubmit you are excplicitly setting the RequestedDate to a new value:

form1.TCMIS_ShortForm.Requestor.RequestedDate.rawValue = Date();

You're getting the black + sign because it's using the long form of the date (including time and time zone, etc.) and the field is too small to hold the data. So you need to set a display pattern on that field.

I didn't notice anything happening with the email field but I think the script is barfing because I didn't fill in all the required fields, I did a quick search through the same script but didn't notice anything odd.

View solution in original post

8 Replies

Avatar

Correct answer by
Level 10

On line 61 of the script on btnSubmit you are excplicitly setting the RequestedDate to a new value:

form1.TCMIS_ShortForm.Requestor.RequestedDate.rawValue = Date();

You're getting the black + sign because it's using the long form of the date (including time and time zone, etc.) and the field is too small to hold the data. So you need to set a display pattern on that field.

I didn't notice anything happening with the email field but I think the script is barfing because I didn't fill in all the required fields, I did a quick search through the same script but didn't notice anything odd.

Avatar

Level 2

If I want to set that date to the current date when the form opens, what event would I use?

Avatar

Level 10

You could use the initialize or layout:ready events, not sure which is best. The "current date" field from the Custom folder of the Object Palette uses the layout:ready event - you could just drag that field onto your form and use that and then just change the date format to what you want, check the FormCalc User Reference for the date formats:

http://help.adobe.com/en_US/livecycle/9.0/FormCalc.pdf

You could leave the code the way you have it so you get the date the form is submitted (in case it is saved and sent at a later date). If you don't want the filler to be able to change the date make the field read only or protected.

I tried changing the display pattern on the field but it doesn't seem to work with the JavaScript date value so you'd need to change your script to get the date format you want. Something along the lines of:

var d = new Date();

fieldName.rawValue = util.printd("yyyy/mm/dd", d);

(And I think you may need to set the display pattern to match.)

Someone else might have to help you with that, I don't use JavaScript for dates much, FormCalc is much easier.

Avatar

Level 2

Always something. Add a few features, and suddenly the validation failure popup message stops being displayed.

https://acrobat.com/#d=x0Our2B7dODkUw1Ygb*JWw

Or is it just me?

Avatar

Level 2

In fact, after adding a message box in another portion of the form, I don't seem to be getting message boxes to come up at all, now.

https://acrobat.com/#d=n0gyVL18IUP1EO4OSmc9dw

Avatar

Level 10

Ok, so there's a few things going on here...

 

You have this:

form1.TCMIS_ShortForm.Requestor.RequestedDate.rawValue = defaultdate; // util.printd("MMM D, YYYY", defaultdate);

and it should be this:

form1.TCMIS_ShortForm.Requestor.RequestedDate.rawValue = util.printd("mmm d, yyyy", defaultdate);

You were assigning the defaultdate value but had the important bit (util.printd...) commented out. And the JavaScript date assignment needs to be lower case "mmm d, yyyy".

Also you'd commented out the new script lines and left the old script in:

//var defaultdate = new Date();

//form1.TCMIS_ShortForm.Requestor.RequestedDate.rawValue = defaultdate; // util.printd("MMM D, YYYY", defaultdate);

form1.TCMIS_ShortForm.Requestor.RequestedDate.rawValue = Date();

The first two lines need to be uncommented and comment out (or delete) the third line.

Instead of putting the script on the form1 layout:ready event I'd put it on the layout:ready event of the date field itself - it took me a bit to figure out where the data was coming from.

You need to make the same changes to the script on btnSubmit.

Don't know if that will fix your validation problem or not.

Avatar

Level 2

I commented out the "util.printd" version of the date-setting line because I wasn't seeing a value in the Requested Date field when I used it. I put back the old version so I could work on other steps.

With your updated code, I still don't see a value in the RequestedDate field when the form opens.

Avatar

Level 10

Here's my version:

https://acrobat.com/#d=9amBHPc*MkcNnBQOGKztQA

I moved the layout:ready code to the date field.