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

How do I lock all fields on submitting form?

Avatar

Avatar
Ignite 3
Level 3
lostfrogg
Level 3

Likes

8 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Ignite 3
Ignite 1
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Ignite 3
Level 3
lostfrogg
Level 3

Likes

8 likes

Total Posts

66 posts

Correct Reply

0 solutions
Top badges earned
Ignite 3
Ignite 1
Give Back 5
Give Back 3
Give Back 25
View profile
lostfrogg
Level 3

23-02-2021

I have a XML PDF form with a number of fields, including a few which auto-populate as per a script (e.g. today's time, today's date). Every time I open the (unsubmitted) form, these fields update as per the system date/time. This is expected.

I want all fields to lock when the user presses the submit button at the end of the form. Currently, even after the form is submitted, the PDF keeps updating those fields every time it is opened!

Accepted Solutions (0)

Answers (2)

Answers (2)

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

24-03-2021

Hi there,

 

I am sorry I kind of mislead you here, as I thought you were handling things a bit differently.

By the look of how you are doing things it is much simpler than I said.

Technically there would be two things you need to consider, because I found an error while trying to fill in your form.

 

1st: As soon as the user hits submit and there's a field in the form that isn't valid, the form will stay read only because you set it "protected" inside the preSubmit event of the submit button.

To avoid this, you can simply set the form's access back to open in the postSubmit event. If you wish to set the form back to open only when the form isn't ready to be submitted I can provide the JavaScript to do so.

 

2nd: To avoid fields to be calculated every time the form is open once the form is locked, all you need to do is add a condition inside the calculate event of those fields like the following:

if (form1.access eq "open") then
     //calculate code
endif

 The code above matches the FormCalc that's used inside the calculate event of Current date and Current time.

If there's any other field that are using JavaScript, the syntax would need to be changed, but the logic is the same.

 

I hope this will help, let me know if you need anything else.

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

25-02-2021

Hi there,

 

my best bet would be having a checkbox in background with visibility's set as hidden which you would set its value checked once the form is submitted.

When your code to set values is executed in the fields, simply verify that the checkbox is unchecked before setting any value.

 

Additionally, you can also have a single statement in the initialize event of each objects to set their access state to readOnly when the checkbox is checked.

 

Hope this will help.

lostfrogg
Thanks Magus069. I'm pretty much a noob when it comes to this and have been trying to learn as I go along. I can put a checkbox on the form with visibility set to hidden - but how do I "set its value checked once the form is submitted"? And how to I have a statement to set their access state to readonly when the checkbox is checked? Thanks
Magus069

Hi there,

 

The following link will explain how to submit a form using JavaScript.

https://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address/

 

Once you execute the code to submit a form, simply change the value of the checkbox to "checked" like the following:

//This should work if your checkbox object's value is either 1 or 0
CheckBox1.rawValue = "1";

//If you don't know for sure what's the object's value, you can use this
CheckBox1.rawValue = CheckBox1.getDisplayItem(0);

 

Once the check box is checked, you can have JavaScript code in the initialize event of each objects to set their access value to readOnly if the submit check box is checked

if (CheckBox1.rawValue == CheckBox1.getDisplayItem(0)){
     this.access = "readOnly";
} else{
     this.access = "open";
}

 

I hope this will help

lostfrogg

Thanks Magus. I'm struggling to follow your instructions. @radzmar posted these instructions on another forum - would these work? This is for date but I would need something similar for time -

 

use this script in the form:ready event of your date field:

if ($.rawValue == null) then$.rawValue = Num2Date(Date(), DateFmt(4))else$.rawValueendif
Magus069
I'm sorry I'm not sure what you are trying to accomplish using this code from radzmar for Time field?? Is this related to the same topic of this thread?
lostfrogg
Yes, related to same topic. Sorry if the code I pasted isn't related. I found it in another thread and I thought it might be an easier way to accomplish what I am trying to do?
lostfrogg
Hi Magus069, I'm still struggling with this; might it be possible to send you my form for you to take a look?
Magus069
Yes you can, I'm sorry I forgot to reply this thread.