Skip to main content
htlfmanning
Participant
April 12, 2017
Answered

How would you set up a variable date field that shows the current date, but then locks upon saving the form?

  • April 12, 2017
  • 1 reply
  • 4378 views

I am trying to set up a disclosure statement that displays the current date when it first displays within an app. Once a customer were to save the form, I need that date to lock to that particular date and no longer update. 

This topic has been closed for replies.
Correct answer Joel Geraci

But they only want it to update once, not each time...


Right... you'd add a document level script that runs each time the file is opened but a conditional statement first checks if the date field has a value set the date only when that's not the case. The field would already be readonly. Something like...

var dateField = this.getField("date");

if (dateField.value == "") {

    dateField.value = util.printd("mmmm dd, yyyy", new Date());

}

If you reset the form before distribution, the date field is blank. It gets filled when the file is opened and assuming they aren't filling it while flying over the international date line, the date that they open the form will be the same date that they save it. The field value gets saved when the file is saved. Not saving the form leaves the value as empty even though a value is visible before you close the file without saving.

1 reply

Legend
April 12, 2017

There's a conceptual problem...won't it lock when YOU save it?

Joel Geraci
Community Expert
Community Expert
April 12, 2017

No need to disable JavaScript either, can just have the code only set the display property when the field has a value other than the default. Then when you are ready to distribute, you just reset the form before saving normally.

Joel Geraci
Community Expert
Joel GeraciCommunity ExpertCorrect answer
Community Expert
April 13, 2017

But they only want it to update once, not each time...


Right... you'd add a document level script that runs each time the file is opened but a conditional statement first checks if the date field has a value set the date only when that's not the case. The field would already be readonly. Something like...

var dateField = this.getField("date");

if (dateField.value == "") {

    dateField.value = util.printd("mmmm dd, yyyy", new Date());

}

If you reset the form before distribution, the date field is blank. It gets filled when the file is opened and assuming they aren't filling it while flying over the international date line, the date that they open the form will be the same date that they save it. The field value gets saved when the file is saved. Not saving the form leaves the value as empty even though a value is visible before you close the file without saving.