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

can't get a yes no to validate correctly

Community Beginner ,
Aug 29, 2024 Aug 29, 2024

Copy link to clipboard

Copied

I have a pdf form where I have made it a required field to click on a yes or no button.  I need one of them to be click when the person tries to save the form, but it never does.   The buttons do have it so that ONLY a yes or a no can be pressed.  Why can't i check for that.  The js works in checking all of the other fields. 

 

Thanks.

TOPICS
Create PDFs , How to , PDF , PDF forms

Views

452

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
1 ACCEPTED SOLUTION
Community Expert ,
Aug 29, 2024 Aug 29, 2024

Copy link to clipboard

Copied

By 'buttons' you mean checkboxes or radio buttons? But it doesn't really matter since 'required' is only useful when you submit the form not when you save it, you can't stop users to save the file, you can only set up alert so when they try to save, an alert can pop to notify them to fill in the fields if they are not filled (file will still be saved).

View solution in original post

Votes

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
Community Expert ,
Aug 29, 2024 Aug 29, 2024

Copy link to clipboard

Copied

What is your script?

Votes

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
Community Beginner ,
Aug 30, 2024 Aug 30, 2024

Copy link to clipboard

Copied

Hi,  for the field that is required it looks like: 

Screenshot - 8_30_2024 , 09_53_41.png

When the script runs after pressing the save button, I do get error messages for all other fields except the button one:

Screenshot - 8_30_2024 , 09_53_27.png

 

the script is as follows:

var error=false;

var message="You must enter a value for the following required fields:\r\n";

var b1=this.getField("Name");
var b2=this.getField("Address");
var b3=this.getField("City");
var b4=this.getField("Zip");
var b5=this.getField("E-Mail");
var b6=this.getField("Signature1");
var b7=this.getField("Signature2");
var b8=this.getField("Signature3");
var b9=this.getField("USS");

if(b1==undefined || b1.value.length<1)

{

error=true;

message+="You must fill out Name before saving\r\n"

}

if(b2==undefined || b2.value.length<1)

{

error=true;

message+="You must fill out Address before saving\r\n"

}

if(b3==undefined || b3.value.length<1)
{

error=true;

message+="You must fill out City before saving\r\n"

}

if(b4==undefined || b4.value.length<1)

{

error=true;

message+="You must fill out Zip before saving\r\n"

}
if(b5==undefined || b5.value.length<1)

{

error=true;

message+="You must fill out E-Mail before saving\r\n"

}

if(b6==undefined || b6.value.length<1)
{

error=true;

message+="You must fill out SCAF COE Signature before saving\r\n"

}

 

if(b9==undefined || b9.value.length<1)
{

error=true;

message+="You must choose USS affiliation before saving\r\n"

}

if(b7==undefined || b7.value.length<1)

{

error=true;

message+="You must fill out CIF-SS Signature before saving\r\n"

}

if(b8==undefined || b8.value.length<1)


{

error=true;

message+="You must fill out CIF-LA Signature before saving\r\n"

}

if(!error)

{

app.alert("Please save the file.", 1); app.execMenuItem("SaveAs");

}

else

{

app.alert(message,3);

}

 

Votes

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
Community Expert ,
Aug 30, 2024 Aug 30, 2024

Copy link to clipboard

Copied

Those fields are either check boxes or radio buttons.  They always have a value.  The value is either the export value of the select box (default is "Yes" for check box, unless you changed it), or "Off" (when no selection is made).  Therefore, value.length<1 will always return false and the condition will not run the remainder of that part of your script that flags the error.  Instead of  b9.value.length<1, use b9.value=="Off" (if b9 is the field you asking about).

Votes

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
Community Beginner ,
Aug 31, 2024 Aug 31, 2024

Copy link to clipboard

Copied

Thanks, i tried it and it still did not work.. I put in: 

}

if(b9==undefined || b9.value.length=="Off")
{

error=true;

message+="You must choose USS affiliation before saving\r\n"

 

and when I clicked on save button, it checked everything else correctly but this one, what did I do wrong?

 

Votes

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
Community Expert ,
Aug 31, 2024 Aug 31, 2024

Copy link to clipboard

Copied

Use:

b9.value=="Off"

Votes

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
Community Expert ,
Sep 01, 2024 Sep 01, 2024

Copy link to clipboard

Copied

LATEST

remove ".length".  It's b9.value=="Off", as I said in my previous post.

Votes

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
Community Expert ,
Aug 29, 2024 Aug 29, 2024

Copy link to clipboard

Copied

By 'buttons' you mean checkboxes or radio buttons? But it doesn't really matter since 'required' is only useful when you submit the form not when you save it, you can't stop users to save the file, you can only set up alert so when they try to save, an alert can pop to notify them to fill in the fields if they are not filled (file will still be saved).

Votes

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