Skip to main content
Participant
January 14, 2022
Answered

Script for checkbox#0 checkbox#1 not show in alert

  • January 14, 2022
  • 1 reply
  • 494 views

Hello,I have found the following Javascript code (from here Re: Check to see if any field is empty)  and join code && f.page =="0" to check page1, text and check box can show right, but if checkbox is same name ex:checkbox#0 checkbox#1  ,it will not showing into alert, how to identify code ,thank you for help!

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

var f= this.getField(this.getNthFieldName(i));

if (f.type!="button" && f.required && f.page =="0")

{ if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name) ; } }

if (emptyFields.length>0) { app.alert("請輸入下列欄位 \n" + emptyFields.join("\n")); } 

This topic has been closed for replies.
Correct answer Thom Parker

The notation "checkbox#0 checkbox#1" is only shown in the Prepare Forms field list panel. They are not real form field names. The #0 and #1 are only there to let you know that they are instances of the same field.  Because they are the same field they share many properties. But since they are different instances they each have some different properties. The collision of these two concepts is the page property. To resovle the inherent conflict it is made into an array of page numbers for the instances of the field. 

 

The way to hand this in code is to convert it into an array. then use array code to do the page check.

So replace   f.page == "0"  (which by the way is already incorrect)

with this    ((typeof(f.page)=="number")?[f.page]:f.page).some(a=> a==0)

 

 

1 reply

Bernd Alheit
Community Expert
Community Expert
January 14, 2022

Info: the page property can be an array.

Participant
January 16, 2022

i can't unedrstand. if the page property can be an array ,then why not show checkbox#0 checkbox#1

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
January 16, 2022

The notation "checkbox#0 checkbox#1" is only shown in the Prepare Forms field list panel. They are not real form field names. The #0 and #1 are only there to let you know that they are instances of the same field.  Because they are the same field they share many properties. But since they are different instances they each have some different properties. The collision of these two concepts is the page property. To resovle the inherent conflict it is made into an array of page numbers for the instances of the field. 

 

The way to hand this in code is to convert it into an array. then use array code to do the page check.

So replace   f.page == "0"  (which by the way is already incorrect)

with this    ((typeof(f.page)=="number")?[f.page]:f.page).some(a=> a==0)

 

 

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