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

Force User to Complete a Field

Community Beginner ,
Feb 09, 2016 Feb 09, 2016

I’m working in Acrobat Pro DC.

I have a dropdown (DepartAnswer) that contains the choices Yes or No. If the user chooses No, they go on to the next field. If they choose Yes 2 text fields appear; one that is Read Only, with default text of: - keep till:  The second field (AvailDate) is empty for the user to put a date.

What has been requested of me is to have the AvailDate field be a mandatory field, if the user has chosen Yes, then there must be a date in the AvailDate field. This form is e-mailed via a button and they do not want the form e-mailed without that field (AvailDate) completed – not tabbed over and left empty.

Is it possible to force the user to complete this field before moving on?

TOPICS
Acrobat SDK and JavaScript , Windows
1.3K
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

correct answers 1 Correct answer

Community Expert , Feb 10, 2016 Feb 10, 2016

- Yes, you're using mailDoc.

- No, that's not correct. You can use this code to do it:

//cToAddr is the e-mail address you are sending to

var cToAddr = ""

//cSubLine is the Subject line with the name of the employee the 24-2812 pertains to

var cSubLine = "24-2812 - " + this.getField("DD1").value + " for " + this.getField("Text2").value + ", " + this.getField("Dropdown6.0").value;

//this produces the e-mail

this.submitForm({cURL: "mailto:" + cToAddr + "?subject=" + cSubLine, cSubmitAs: "PDF"});

...
Translate
LEGEND ,
Feb 09, 2016 Feb 09, 2016

You can mark the field as Required and the submit form action won't be allowed to take place unless it it filled-in.

Another approach is to use JavaScript, where you have the opportunity to check fields more completely and give more helpful feedback to the user. The script would first check the required fields and only proceed with the submitForm statement if everything checks out.

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 Beginner ,
Feb 09, 2016 Feb 09, 2016

Ok, this may sound silly, but I have done that.  On the AvailDate field I have checked Required under the General tab, the outline of the field turns red. But I am still able to click on the button to e-mail the form and it does so with AvailDate empty.

Am I doing something wrong?

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 09, 2016 Feb 09, 2016

How are you emailing the document? There are different methods, and the "required" fields will only be checked when you are doing a true forms submission. If you are using the Doc.mailDoc() method for example to email your document, that is not a forms submission, and it will therefore not check the required 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 Beginner ,
Feb 09, 2016 Feb 09, 2016

Under the button properties on the Actions tab for Select Trigger I have Mouse Up, for the Select Action I have Run a JavaScript.

This is the coding I have associated with the button:

//cToAddr is the e-mail address you are sending to
var cToAddr = ""

//cSubLine is the Subject line with the name of the employee the 24-2812 pertains to
var cSubLine = "24-2812 - " + this.getField("DD1").value + " for " + this.getField("Text2").value + ", " + this.getField("Dropdown6.0").value;

//this produces the e-mail
this.mailDoc({bUI:true, cTo: cToAddr, cSubject: cSubLine});

The users wanted the subject line to be completed based on some of the fields in 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 09, 2016 Feb 09, 2016

The mailDoc method doesn't enforce the required fields validation before executing. You'll have to do it yourself using a script, or switch to using the submitForm method, which does makes sure that all of the required fields are filled-in before sending the file to the target URL.

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 Beginner ,
Feb 09, 2016 Feb 09, 2016

So the way that I have the button set up is the mailDoc method?

If I use the submitForm I don't have the ability to place field values in the subject line as I do with JavaScript...correct?

What would be the script to get the user to enter information into AvailDate?

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 10, 2016 Feb 10, 2016

- Yes, you're using mailDoc.

- No, that's not correct. You can use this code to do it:

//cToAddr is the e-mail address you are sending to

var cToAddr = ""

//cSubLine is the Subject line with the name of the employee the 24-2812 pertains to

var cSubLine = "24-2812 - " + this.getField("DD1").value + " for " + this.getField("Text2").value + ", " + this.getField("Dropdown6.0").value;

//this produces the e-mail

this.submitForm({cURL: "mailto:" + cToAddr + "?subject=" + cSubLine, cSubmitAs: "PDF"});

- Using the code above they will not be able to submit the file unless they filled in all required fields first.

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 Beginner ,
Feb 10, 2016 Feb 10, 2016

Thank you for the information and the coding, it worked perfectly. Exactly what I was looking for thank you!

You all are awesome.

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 Beginner ,
Feb 10, 2016 Feb 10, 2016

I ran into an issue; because the AvailDate filed is checked required and AvailDate only appears if the dropdown (DepartAnswer) is Yes, if I choose No for the dropdown (DepartAnswer) I cannot e-mail the form because AvailDate is a required field.

Is there a way to have a field required without checking the required box?

In other words, is there some type of coding that I can use so if AvailDate is visible then entering information into the field is required, however if it is hidden it can be blank and the form can still be e-mailed?

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
LEGEND ,
Feb 10, 2016 Feb 10, 2016

You can use JavaScript to make the field required or not, just like you make those two text fields visible or not, depending on the state of the dropdown. The property name is "required".

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 Beginner ,
Feb 10, 2016 Feb 10, 2016

How would I do that? This is the coding I have for AvailDate:

var v = this.getField("DD1").value;

var y = this.getField("DepartAnswer").value;

if(v=="Departing"&&y=="Yes")event.target.display=display.visible;

if(v=="Departing"&&y=="No")event.target.display=display.hidden;

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
LEGEND ,
Feb 10, 2016 Feb 10, 2016

f (v == "Departing" && y == "Yes") {

     event.target.display = display.visible;

     event.target.required = true;

} else if (v == "Departing" && y == "No") {

    event.target.display = display.hidden;

    event.target.required = 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
Community Beginner ,
Feb 10, 2016 Feb 10, 2016
LATEST

Oh, thank you so much George!  Just what I needed to complete this 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