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

making a text field mandatory before user can continue filling form

Lolianna
Registered: Sep 22 2008
Posts: 21
Answered

I am trying to make a specific text field required/mandatory before the user can proceed to the next fillable item in the form.

I have been unable to locate specific instructions or code for achieving this end.

Neither form nor the data will not be "submitted" electronically as it is an internal form. The user will print, sign, and submit in person. The goal is to get them complete the text field.

Any assistance or direction will be helpful. Thank you.

My Product Information:
Acrobat Pro 8.1.3, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Will any entry in the field suffice (i.e., a single character), or is there a specific type/format that needs to be met, such as a complete phone number?

An approach you can take is to check the field value in the field's Validate event. If it's OK, then enable the subsequent fields (e.g., making them visible and/or not read-only. If it doesn't check out, make the fields hidden/read-only.

George
Lolianna
Registered: Sep 22 2008
Posts: 21
George,

The intended content of the field is a paragraph or two of text. There are no specifics beyond that. I guess if there was a way to require a minimum number of characters...
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
OK, here's a skeleton of a routine that you can use as the field's Validate script:

(function () { // Set the minimum number of charactersvar min_chars = 25; // If number the of characters is less than the minimum,// set a flag to indicate that fields should be disabledvar bDisable = (event.value.length < min_chars); // Enable/Disable fields heregetField("Text1").readonly = bDisable;getField("Text2").readonly = bDisable;// Continue with any other fields here })();

This is the bare minimum, but you should get the idea. When you disable a field, you might want to instead make it hidden and also reset its value. You should also probably add code to inform the user (e.g., app.alert) if the entry is lacking and why.

Consider exactly what should happen if the user initially fills in the field and subsequent fields, and then goes back and removes the entry of the required field.

George
Lolianna
Registered: Sep 22 2008
Posts: 21
Thanks for the starter code, George. If I use this approach, I'm going to have to disable (or or hide) over 800 fields that follow the initial field. Plus, as you pointed out, I need to address completion of the form and then removal of previously entered information.

Perhaps I would be better off considering a way to make following pages in the document inaccessible without completion of the field, rather than the fields themselves, i.e., fewer than 25 characters entered in the field prevents viewing pages two and three. Is that feasible?

Loli
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
That's even harder.

I often do this sort of thing, and when I need to disable a large number of fields I set up a routine that loops through all of the fields and disables them, unless the field is included in a list of fields to exclude that I've set up. The code can be simplified by using a strict field naming convention.

George
Lolianna
Registered: Sep 22 2008
Posts: 21
I think this project has just passed beyond my well of knowledge and time available, not actually being a programmer. I think I'll start with code that alerts the user when the minimum number of characters hasn't been met. Thank you for your time.

L
Lolianna
Registered: Sep 22 2008
Posts: 21
I found code posted on the site that shows how to disable and/or enable form fields and gray them out. The code sets up a document javascript for the enable and disable, then uses that in conjunction with radio buttons to determine when the form fields are disabled and when they are enabled.

Can I use the same method for my issue, but have the trigger be the number of characters entered in the text field? If so, what would the code be? I'm not sure if it is possible to set up an if/else statement that would suffice.

Assistance on this would be appreciated. Thank you.

L
j_shell
Registered: Nov 16 2007
Posts: 25
Here is a variation on what George suggested that might work for you. For your text field, add this as an On Blur action:

var k = getField("read");var l = getField("Text2"); if ( l.value.length < 10) {k.readonly = true;app.alert("Enter alert text!");l.setFocus();}elsek.readonly = false;

Then, for all the fields after the text field, use the naming convention of read.[i]WhateverYouWantToNameIt[/i] for the field name. Also, in the General tab of the properties box, set these fields to "read only." You should be able to do this pretty quickly by drag-selecting all the fields at once, right-clicking and selecting "read-only" under the General tab. Unfortunately, you will have to change the field names separately.

This should cause all the fields following your text box to be read-only when the document opens. When users type more than x charaters in the box and then change the focus out of the box, all the following fields should be editable.

Hope this helps,
Justin
Lolianna
Registered: Sep 22 2008
Posts: 21
Justin,

This works well. It seems to solve the problem I was having over the user totally by-passing the required field.

Thank you both for your assistance.

L