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

Copy link to clipboard

Copied

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

Views

3.4K

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

correct answers 1 Correct answer

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. 

 

 

 

 

Votes

Translate

Translate
New Here ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

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

 

Thank You

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

Hi Felicy,

Kindly find attached.

Thank You

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

Copy link to clipboard

Copied

Hi try67!

 

May you please help me with the 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 Expert ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

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;

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

Copy link to clipboard

Copied

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

😞

 

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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 !

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

Copy link to clipboard

Copied

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;
}	

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

Copy link to clipboard

Copied

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 !

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

You should use both codes, yes.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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"});

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

Copy link to clipboard

Copied

> 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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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!

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

Copy link to clipboard

Copied

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>"});

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

Copy link to clipboard

Copied

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?

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