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

How do I make the dropdown required by not allowing the "Please Select Option" as selected answer

New Here ,
Feb 23, 2022 Feb 23, 2022

Greetings!

May you please help me on how do I make the dropdown required and not allowing the "Please Select Option" as the selected option by the user.

Please see attached screenshot:

Almi23147849yqdz_1-1645611794346.jpeg

 

Thank you and hoping for your reply.

 

TOPICS
PDF forms
7.0K
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 ,
Feb 23, 2022 Feb 23, 2022

A submit will be blocked when a field is both required and set to it's default value.  So make "Please Select" the default. I don't see any need for the script. 

 

 

 

 

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
New Here ,
Feb 23, 2022 Feb 23, 2022

Furthermore, this should not allow the user to submit the form unless it has met the requirement.

 

Thank You

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 ,
Feb 23, 2022 Feb 23, 2022

You will need to validate the selection using a script, before sending the file.

Is this the only field you want to check, or are there more?

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 ,
Feb 23, 2022 Feb 23, 2022
Hi Felicy,

Kindly find attached.

Thank You
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 ,
Feb 23, 2022 Feb 23, 2022

Hi try67!

 

May you please help me with the script?

 

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 ,
Feb 23, 2022 Feb 23, 2022

Set that field as required and then use this script as 'Validation' of that same field:

event.target.required = event.value == "Please Select Option" ? true : false;

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 ,
Feb 23, 2022 Feb 23, 2022

Almi23147849yqdz_0-1645620103100.pngAlmi23147849yqdz_1-1645620148058.png

Hi Nesa, thank you for your reply. I have done what you have said but its still allowing me to submit the form

😞

 

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 ,
Feb 23, 2022 Feb 23, 2022

Since it's validation script you need to trigger script by changing value and then back to default or set field to required manually for first time.

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 ,
Feb 23, 2022 Feb 23, 2022

I went to review mode, then tried to reselect the option "Please Select Below", unfortunately its still allowing me to submit the form 😞

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 ,
Feb 23, 2022 Feb 23, 2022

A submit will be blocked when a field is both required and set to it's default value.  So make "Please Select" the default. I don't see any need for the script. 

 

 

 

 

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 ,
Feb 23, 2022 Feb 23, 2022

You need to answer my question first. But generally speaking search the forum for "validateRequiredFields", which is a function I wrote that does just that.

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 ,
Apr 22, 2022 Apr 22, 2022

Hello ! I was looking for the same code and i've been looking into the forum to find the code but i can't seem to find it. Would it be possible for to provide it here ? Thank you so much !

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 ,
Apr 22, 2022 Apr 22, 2022

Here's the generic function that will do that. It returns a boolean which can be used later on to decide whether to submit the file or not:

 

function validateRequiredFields(doc) {
	var emptyFields = [];
	for (var i=0; i<doc.numFields; i++) {
		 var f = doc.getField(doc.getNthFieldName(i));
		 if (f!=null && f.type!="button" && f.required && f.valueAsString==f.defaultValue) {
			emptyFields.push(f.name);
		}
	}

	if (emptyFields.length>0) {
		 app.alert("You must fill in the following fields:\n" + emptyFields.join("\n"));
		 return false;
	}
	return 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
New Here ,
Apr 25, 2022 Apr 25, 2022

Hello,

 

Thank you so much for the code. However, I can't seem to see where I should be putting the code in my form ? Also, is there any fields in the code that requires to be « personalize » with the name of the field in my form ? If so, which ones ?

 

Thank you so much for your help !

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 ,
Apr 25, 2022 Apr 25, 2022

This is a generic function. If you want to use it as a part of your submit-button you can do so like this:

 

if (validateRequiredFields(this)) this.mailDoc({cTo: "me@server.com"});

 

And no, you should not change anything in the code of the function itself. It will automatically pick up and validate all the required fields in your file.

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 ,
Apr 25, 2022 Apr 25, 2022

So I should no be using the code you previously provided ?

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 ,
Apr 25, 2022 Apr 25, 2022

You should use both codes, yes.

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 ,
Apr 25, 2022 Apr 25, 2022

Ok, so where in my form should I be using the first code you provided ?

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 ,
Apr 25, 2022 Apr 25, 2022

You can place it all under the submit button's Mouse Up event.

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 ,
Apr 25, 2022 Apr 25, 2022

I'm so sorry. I already have a mouse up event right now for « send form » in which I inserted « mailto:me@exemple.com Â» in the « Enter a URL for this link » field. Should I remove this event and create a new mouse up event for the submit button or have both event ? 

Also the submit button event you are talking about, is it a mouse up event with the action « Execute a script Javascript » ? And is so, how should I put the 2 codes in there (like this) ? : 

 

function validateRequiredFields(doc) {
var emptyFields = [];
for (var i=0; i<doc.numFields; i++) {
var f = doc.getField(doc.getNthFieldName(i));
if (f!=null && f.type!="button" && f.required && f.valueAsString==f.defaultValue) {
emptyFields.push(f.name);
}
}

if (emptyFields.length>0) {
app.alert("You must fill in the following fields:\n" + emptyFields.join("\n"));
return false;
}
return true;
}

if (validateRequiredFields(this)) this.mailDoc({cTo: "me@server.com"});

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 ,
Apr 25, 2022 Apr 25, 2022

> Should I remove this event and create a new mouse up event for the submit button or have both event ?

- You should remove that event and create a new one with just the "Execute a JavaScript" command.

> Also the submit button event you are talking about, is it a mouse up event with the action « Execute a script Javascript » ?

- Yes.

And is so, how should I put the 2 codes in there (like this) ? ... :

- Yes.

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 ,
Apr 25, 2022 Apr 25, 2022

OMG thank you ! You're a savior !!! 🙂

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 07, 2022 Jul 07, 2022

Thank you very much for the script! In my situation, I want to "Submit a Form" to an html address instead of sending it by email, how can I embed the javascript to submit after this validation?

I tried adding a separate action to the buttom but after the "warning" pop-up comes, it will still send through.

 

Much appreciated to any help at all!

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 08, 2022 Jul 08, 2022

You have to do it all using a single script. In the code above replace the this.mailDoc command with this:

this.submitForm({cSubmitAs: "HTML", cURL: "<Enter your target URL here>"});

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
Explorer ,
Aug 03, 2022 Aug 03, 2022

Can this code be used somehow other than with a submit button? We save the form locally and then upload to Basecamp, so we neither email nor submit to a particular URL.I would like to validate that required fields are completed before saving the file. Is there a way to integrate this into my save as button perhaps?

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