These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Required Fields Question

soleydflr
Registered: Oct 11 2010
Posts: 13

I have Adobe 9.0 Pro and have a form that I have required fields in. I copied a javascript from a Developers Tips page so that On Blur, the user must enter information in a particular field before going on. It does work but you cannot get out of the warning. Here is what I copied:
 
f = getField(event.target.name)
if (f.value.length == 0)
 {
 f.setFocus()
 //Optional Message - Comment out the next line to remove
 app.alert("This field is required. Please enter a value.")
 }
 
If this is the correct javascript to use, is there a piece missing to allow the user to go to the field and fill it in? If so, what needs to be added? If this is not correct, can you tell me what I can put in so that people cannot go further without completing the required field?
 
Thank you.

My Product Information:
Acrobat Pro 9.3.1, Macintosh
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1875
Are you saying that the app.alert is shown whether or not the field is competed?
soleydflr
Registered: Oct 11 2010
Posts: 13
Yes, the alert will not go away and I had to force quit my software to be able to exit.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can allow for an exit.

if (this.getField(event.target.name).value.length == 0) {
if(app.alert("Please complete this required field", 2, 2) == 4)
this.getField(event.target.name).setFocus();
}

or

// get field object for testing
var f = this.getField(event.target.name);
// get field value
var cResponse = f.value;
do {
// test for length of value
if(cResponse.length == 0) {
// no response
cResponse = app.response("Please enter required value:", "Required Entry Required!");
// allow an exit
if (cResponse == null) break;
} // end if
} while (cResponse == 0); // loop until a response
// set field value
if (cResponse != null) f.value;


George Kaiser

soleydflr
Registered: Oct 11 2010
Posts: 13
I just tried your second suggestion and I love that it opens a dialog box to enter the missing info, but it does not place it in the field missing it. Is that supposed to do that?
soleydflr
Registered: Oct 11 2010
Posts: 13
I just tried your first suggestion and it works great too. But can I change the Yes or No to an Okay and only allow for the entry to take you back to the empty field when OKAY is clicked?
soleydflr
Registered: Oct 11 2010
Posts: 13
I tried playing with suggestion 1 and I got it to work the way I needed. Tell me, what do the numbers represent in your first suggestion 2,2 ==4? I changed them to 1 ==1 and it works but I don't want to do something that messes things up badly.
soleydflr
Registered: Oct 11 2010
Posts: 13
I still need some help on this item. I have four fields that I want to use as Required such as Name, Birthdate, etc. and I don't want them to be able to say NO to entering a required field. So, as stated in my previous question, I changed your script to be ,2 ==4 and it works but does not take be back to the original field requesting filling in, it takes me to the next field. So my user would have to go back to the previous field to fill in. What do the ,2,2 ==4 refer to in this example? When I use only one 2 it gives me an OKAY rather than a No, Yes option. So I want to use that but how do I get it to put the cursor back at the field?

Please help!!!!
soleydflr
Registered: Oct 11 2010
Posts: 13
I have another question: If I am creating required fields that only allow you to enter something without the option to continue without entering a field, how do I save a blank form form so that I can send it to people. Seems like I have created a monster for myself because I have to fill something in to get past my required fields message yet I want a blank for for sending out.

Also, If I have a date field, what is the javascript that I can enter to have it pull up the current date in this field?

Thank you in advance for all of your help.
mrsneely77
Registered: Sep 3 2008
Posts: 24
Were you able to get your fields to work properly? I am having some of the same problems.

I am a Forms and Records Analyst for the Washington State Department of Retirement Systems. This position in new to the agency so I am setting the standards.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
@mrsneely77
You might want to start a new post, specifying what exactly the problem is.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com