Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Lock and Unlock with same button

New Here ,
May 14, 2020 May 14, 2020

Hey all,

 

I'm trying to create a form that requires information from 1 page and filters it to the next. I want the user to be able to lock the information with a button but also be unlock the information if they need to change something with the same button. I can do it with 2 buttons, but for easier use I would like, if possible, to use 1 button for both functions. Thanky you in advance.

TOPICS
How to , PDF forms
2.1K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
May 14, 2020 May 14, 2020

Use a checkbox.  Here is some sample code for makeing fields read only based on the checked/unchecked state of the checkbox, 

MouseUp "Run a JavaScript" action

 

if(event.target.value == "Off")

{// Unlock field when unchecked

     this.getField("SomeField").readOnly = false;

}

else

{// Lock Field when checked

     this.getField("SomeField").readOnly = true;

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
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
Community Expert ,
May 14, 2020 May 14, 2020

Hi,

 

How are you locking the fields?  if you are using the read-only property you could just assign it to the other on button click

 

something like

var f = this.getField("myTextField");

 f.readonly = !f.readOnly;

 

This would swap the setting each time the button is clicked.

 

Regards

 

Malcolm

Translate
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
Community Expert ,
May 14, 2020 May 14, 2020

Use a checkbox.  Here is some sample code for makeing fields read only based on the checked/unchecked state of the checkbox, 

MouseUp "Run a JavaScript" action

 

if(event.target.value == "Off")

{// Unlock field when unchecked

     this.getField("SomeField").readOnly = false;

}

else

{// Lock Field when checked

     this.getField("SomeField").readOnly = true;

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
May 14, 2020 May 14, 2020

Thank you very much! This is an easier fix than two buttons that switch visibility.

Translate
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 22, 2021 Jul 22, 2021

This code makes perfect sense to do what I'm trying to do but for some reason it doesn't work on my form. Would anyone be able to look at this and see where I'm going wrong? I have a checkbox and when ticked I want to make the fields read-only and/or locked. These four fields repeat throughout the form though, wonder if that's the problem. I tried the fields with the notation as it appears on the form (e.g., Centre ID#0 etc) but that doesn't work either. Can anyone help? 

 

if(event.target.value=="Off") {
this.getField("Centre ID").readOnly = false;
this.getField("Study ID").readOnly = false;
this.getField("Baseline Date").readOnly = false;
this.getField("Baseline Assessor").readOnly = false;
}
else
{
this.getField("Centre ID").readOnly = true;
this.getField("Study ID").readOnly = true;
this.getField("Baseline Date").readOnly = true;
this.getField("Baseline Assessor").readOnly = true;
}

Translate
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
Community Expert ,
Jul 22, 2021 Jul 22, 2021

Look in the console window to see if any errors are reported. 

 

There is a video on using the console window here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
Community Expert ,
Jul 22, 2021 Jul 22, 2021

There's an error in that code. The name of the property for fields is "readonly". Confusingly, it's "readOnly" for annotations, but not for fields.

Translate
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
Community Expert ,
Jul 22, 2021 Jul 22, 2021

Ahhhh!  That one always gets me.  It's "readOnly" for annotations and "readonly" for fields.   

Thank Gilad, good catch. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
Community Expert ,
Jul 23, 2021 Jul 23, 2021

Happens to the best of us! 🙂

 

Translate
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 28, 2021 Jul 28, 2021
LATEST

Oh I see! I learn so much here. Thank you both! It is working like a dream now 🙂 

Translate
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