Checkbox with password requirement

New Here ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

Hello,

 

We (my small team and I) trying to create a form where part is filled out be the applicant and then another part filled out be the "office reviewer". We have it set up so that the applicant can complete the form, then the review checks a box and new fields appear with instructions, areas that do calculations. etc.. This is all working great. When the check box is check everything that is need appears and when unchecked it goes away. The issue is we dont want the applicant to be able to check the box and see these instructions, as it could lead them to providing inaccurate information to ensure they meet specific eligibility criteria. So we thought of requiring a password when the box is checked and we have been able to get a password window to appear when you check the box ("Check box127").  The issue we are having is even with the password the content appears if its the right password, wrong, or user hits cancel. We know it's because the box is still checked regardless. I think we need an "if...then" scrip around the app script but have not been able to figure it out. Something that says if the password is entered correct then check the box, if entered incorrectly do not check the box and if canceled entereed do not check the box. Here is the script I am using for the password app (not the actual password though, we will change that):

var correctPassword = "1234";
resp = app.response("Enter the password:");
if (resp==null || resp!=correctPassword) getField("outside").setFocus();)

 

Any help is greatly appreciated. Our team is mostly new to Javascript. We have been pretty successful so far but we are all learning as we go. 
 

TOPICS
Create PDFs , How to , JavaScript , PDF forms

Views

67

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

Hi,

 

As anyone using the form could find out the password, I don't think this is the way to go.

 

If all the review have acrobat you could have two forms, and export the data from the first and import it into the second, and then there wouldnt be anything to hide.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

Change the last line to:

this.getField("outside").checkThisBox(0, resp==correctPassword);

As mentioned, though, this is far from secure, so just keep that in mind...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

Thank you. We are very aware this is not the most secure. Working with that same idea as a lock, it is mostly there to keep honest people honest. The overall intent is just to make this hidden information not easy to get to for those that do not readily have the password.

 

I updated the coding to the following below and its doing the same thing. Doesnt matter if you put in the correct password, wrong password or hit cancel the box still is either checked or unchecked and the fields hide/unhide. 

var correctPassword = "1234";
resp = app.response("Enter the password:");
this.getField("outside").checkThisBox(0, resp==correctPassword);

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

Yes, this code will check or uncheck the box based on whether the user's input matches the password you defined. It doesn't hide or show any fields, though.  Isn't that what you wanted? If not, please clarify.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Hello Try67,

 

Yes that is what I want it to do but it's not working that way. Hide/show fields aside. If I check the box, the app appears and I put in the correct password then yes, the box does get checked and it works as intended. But here is the issue. Even if I put in the wrong password and press ok, the box still gets checked. Same with "cancel". If I press cancel, the box still gets checked. That's the issue we keep running into. We want it to not check the box if the wrong password is entered or cancel is selected. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Can you share the file?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Hi Try67,

 

I included a draft version. Its still in early stages of development and we are all working on different pieces. The checkbox with the coding I am talking about is found on page 5 in the top right corner. It has two scripts attached to it. The first is the one for the password the other is the hide/reveal which is working as we intend it to. I did change the script around for the password some to include error messages and such and tried to account for incorrect passwords so it differs from what is in our chat above but I am still having the same issue.  

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

There are multiple issues here:

1. You can't use the Mouse Up event for this. The user is already ticking or unticking the box, and the code will conflict with that. You need to trigger the script in some other way. I would just use a button for this. You don't need a check-box at all. If you want to have one then make it read-only and have the code tick on untick it.

2. You must only use a single script for all of your commands. Don't split it into two actions, as you can't control the order in which they execute.

3. You're referring to an incorrect field name in your code and it's causing an error:

TypeError: this.getField("outside") is null
6:Field:Mouse Up

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

Thank you Try67. I had floated the idea of using a button but figured the issue would be the same regardless but knowing the issue with the mouse up event makes sense.

 

How would I go about coding this as one script? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

LATEST

Just combine the codes. You will need to replace all instances of event.target with this.getField("Check Box127"), though.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines