Copy link to clipboard
Copied
Hi all,
First of all, please know that I have just spent over an hour going through as many threads as I can regarding required fields but none of them seemed to answer my question since most dealt with online forms or more complex issues.
All I am trying to find is some way of enforcing required text fields on a pdf form. There are three fields at the top of my form that need this. I would like to prevent the user from being able to save or print unless these fields are filled out.
Thank you very much in advance for your help:)
Best regards,
Christine
Copy link to clipboard
Copied
FWIW, I've found that people quickly get used to forms that behave the way I showed, and even appreciate it since it helps reduce invalid entries, unlike what I'm about to show below...
You could do something like the following in the On Blur event, similar to what was suggested in the article you linked to:
// On Blur script
if (!event.target.valueAsString) {
app.alert("[Provide field description here] must be complete. Please enter something, anything", 3);
}
Note that I left out the setFocus call.
Copy link to clipboard
Copied
You cannot prevent either. You can use the "Document Will Save" and "Document Will Print" events to alert the user (app.alert) that certain fields are not complete, but that's it.
Copy link to clipboard
Copied
Thank you:)
Here is an alternative I would like to try to do then...perhaps force the user to fill in the field/s before being able to move on to the rest of the form.
I found this webpage: http://cookbooks.adobe.com/post_Enforcing_Required_Fields-16435.html
It describes how to do this by inserting javascript to the "On Blur" action of the field that is required. I am having a problem with that script tho' - I seem to get 'locked' and unable to do anything else after the alert window pops up. If I have just one required field it works fine, but I have 3 that are right underneath eachother, with a separate instance of the script being applied to each field. I tried to the variation that was supplied by another user futher down the page but am having the same issue.
Can you give me any further advice or help regarding this? I have Acrobat 9.1.2.
Thank you again in advance:)
Christine
Copy link to clipboard
Copied
I would not use the blur event for this, but rather the Validate event, assuming you're talking about a text field or combo box. The validate script would see if the field value is empty, and if so, set the other fields to hidden and reset their values. If the field is not empty, the other fields would be set to display.
Copy link to clipboard
Copied
BTW, what I'm suggesting is what the author of that article is rejecting. I dislike using the setFocus method for stuff like this and find it a better user experience to do what I suggested. If you went with the other approach, the user could just avoid that field and move on with the subsequent fields.
Copy link to clipboard
Copied
George,
I just read this response from you... do you think you could paste in the code for me exactly as you think would work best? I am not exactly sure what needs to be done.
Thank you,
Christine
Copy link to clipboard
Copied
Yes, you would use completely different code. Here is a simple example that enables two text fields after the text field to which it is attached has a value (isn't blank):
// Validate script for text field
(function () {
// Get references to the subsequent fields to control
var f1 = getField("other_text_field1");
var f2 = getField("other_text_field2");
// Reset the fields
f1.value = f1.defaultValue;
f2.value = f2.defaultValue;
if (event.value) { // Show the fields if this field is not blank
f1.display = display.visible;
f2.display = display.visible;
} else { // Otherwise, hide the fields
f1.display = display.hidden;
f2.display = display.hidden;
}
})();
Note that the script can be simplified if you use a heirarchical naming convention for the subsequent fields. We discussed a similar situation just yesterday at: http://acrobatusers.com/forum/forms-acrobat/set-form-skip-question-depending-answer-another
so you could look there for more information on this approach.
Copy link to clipboard
Copied
Thank you George:) I got this to work but it isn't the exact solution I am looking for:(
Knowing everyone over here, they will probably think that there is something wrong with the form because there are no alert messages. Is there any way to make things work so that an alert message simply pops up if they try to leave/exit a field before filling it in. I would prefer this behaviour instead of disabling some of the fields because a user may happen to click on one of those disabled fields first and then wonder why they cannot enter any information.
Thank you so much for your help and your patience:)
Kind regards,
Christine
Copy link to clipboard
Copied
FWIW, I've found that people quickly get used to forms that behave the way I showed, and even appreciate it since it helps reduce invalid entries, unlike what I'm about to show below...
You could do something like the following in the On Blur event, similar to what was suggested in the article you linked to:
// On Blur script
if (!event.target.valueAsString) {
app.alert("[Provide field description here] must be complete. Please enter something, anything", 3);
}
Note that I left out the setFocus call.
Copy link to clipboard
Copied
George,
Thank you very much! Your last response was very helpful... that will work perfectly for what we need right now:)
This whole thread has been *very* informative as a matter of fact and a good learning experience! It was wonderful to learn about the other options you presented as well... I can put that to good use in the future!
Best regards,
Christine
Copy link to clipboard
Copied
This code works only if they go to that field and then skip it right?
What if the user does not even go on the field and jumps to the next question, then onBlur wont work, will it?
Any solutions to that? Otherwise it works great
Copy link to clipboard
Copied
George or akshayny1 - that is exactly the solution I am looking for...
I think I need to run some Javascript in the submit button I have on my form, so far I tried using the following ... the checkbox that everyone is bypassing is called Confirmed...
the following does not seem to work - anyone help me:
if (Confirmed.value.length == 0)
{
Confirmed.setFocus()
//Optional Message - Comment out the next line to remove
app.alert("The confirmation box must be checked. Please confirm.")
the full set of actions on my submit button are:
the above, then file>save as, then submit which emails the form
georgesz
Copy link to clipboard
Copied
You can use below to reset the form, so the user will have to fill in the form otherwise he will loose all details
// To reset the form if the x mark has been clicked
// avoiding the required fields then the form will be reset
// this command should be put in preSave state
// Run the validation on click
var namevalidate = xfa.form.form1.execValidate();
if (namevalidate){} else{
xfa.host.resetData();
}
#@Kurdistan!
#@Karwan!
Copy link to clipboard
Copied
This script might work in a LiveCycle Designer form, but it will not work in an Acrobat form.
Copy link to clipboard
Copied
I used some of your code, but chose to apply it to the print button. It looked like this:
var error=false;
var message="You must enter a value for the following required fields:\r\n";
var b1=this.getField("FIELD_NAME");
if(b1==undefined || b1.value.length<1)
{
error=true;
message+="You must fill out ______________ before printing\r\n"
}
if(!error)
{
this.print();
}
else
{
app.alert(message,3);
}
I also added a save and clear form button that could be used even if the required fields were not complete, and then I hid the menu bars for when the form opens. This forces most users to fill in those fields so they can print the form. Of course, this relies on the idea that you will be printing and live signing forms...
Copy link to clipboard
Copied
Hi, liked your reply and script. I have 8 fields that need to be required before the form could be printed, they are Name, Address, City, Zip, E-Mail, Signature3, Signature4, Signature5.
Thanks for you great help!
Copy link to clipboard
Copied
George,
I am using the form fields properties box to enter the javascript code. Am I supposed ot be doing it another way?
If this properties dialogue box is what I am supposed to be using, then under the actions tab I don't see a "Validate" option for the events.
I instead went to the Validations tab, chose to "Run custom validation script" and entered the code there. This didn't work for me tho'... so I am sure I must be doing something wrong here:( Forgive me... I am a newbie to working with JS in Acrobat.
Thank you,
Christine
Find more inspiration, events, and resources on the new Adobe Community
Explore Now