Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Disable scrolling text?

Avatar

Former Community Member
I have seen similar posts but have found no answer. I would like to limit text entered into a field by the actual parameters of the drawn text box. An option which was simple in Acrobat Professional (uncheck scroll long text). While I appreciate any help in this matter, I must warn you that I know nothing about scripting. If the answer lies in adding script to the form field properties, I would need step by step instruction. Thanks in advance.
7 Replies

Avatar

Former Community Member
Unfortunately, there's no way to do this other than to use scripting. At least it's not too complicated (even though it may appear complex at first, hopefully you'll think it's simple in the end).



When you create fields directly in Acrobat (without using Designer), you're creating AcroForm fields. As you say, there's a "scroll long text" property on these fields which you can uncheck to limit the amount of text to the visual area of the field.



When you create fields in Designer and then open the form in Acrobat, there's a second layer for each field: An XFA Form Field. Script that you write in Designer on fields operate on the XFA layer. It's possible, however, to write script which accesses the AcroForm field properties (properties on the Acrobat Form Field object which wraps the XFA Form Field object) by getting access to the Acrobat Document Object and using its getField method.



In an XFA event like a text field's Enter event (you can get there by selecting the text field, choosing the Script Editor from the Window menu and selecting "enter" from the Show property on the top left corner of the Script Editor), the statement "event.target", when the Script Language is set to
JavaScript, refers to the Acrobat Document Object. From there, you can use the getField method to access the AcroForm "wrapper" for the text field by giving it its address. Once you have that AcroForm object, you can finally set the value of the "doNotScroll" property which is the equivalent of unchecking the "scroll long text" property in Acrobat.



So for a text field named, "TextField1", on the first page on a form, you would do it like this:



event.target.getField("form1[0].#subform[0].TextField1[0]").doNotScroll = true;




I've attached a sample form which is setup correctly and, when run in Acrobat, gives you a multi-line text field in which you can't enter more text than that which fits in the field's area.



I tried to make this as clear as possible but I'm sure you'll have questions so let me know what they are and I'll try to answer them.



Stefan

Adobe Systems

Avatar

Former Community Member
Stefan,

Thanks for the information and the example file. It has been very helpful. I do however have a follow-up question. I have created a new form from an imported word document which was designed using tables. When the file is converted the generated textfields appear within a subform and in some cases a subform within another full page subform. I was hoping that you could give me an example of the javascript I would need to apply this same function to a textfield within a subform. Thanks again for the help.

Avatar

Former Community Member
Essentially, all you need to do is put the following script on the Enter event of all text fields for which entering text should be limited to their visual extent:



event.target.getField("
AcroFormSOMExp").doNotScroll = true;


The most difficult part is figuring-out what the
AcroFormSOMExp expression is which references the Acrobat AcroForm object which represents the underlying XFA Form Field object.



So how about we write a script which builds the AcroForm SOM Expression given any object and then you can place the script on any field inside any number of nested subforms and it should work without any extra effort?



The trick lies in knowing how AcroForm SOM Expressions are coded. I won't go into the details here but basically, unlike XFA SOM Expressions, the expression must always start at the root subform ("form1" by default) and every name in the expression must have a specified index.



I've attached a sample form which is "version 2" of the one I posted earlier. In this version, the text field is wrapped in another unnamed subform. I've also created a script object off of the root subform ("form1") in which I implemented two functions that are needed to generate the AcroForm SOM Expression for a specified object.



Script objects are handy because they allow you to reuse scripts instead of copying and pasting them all over the place. You can insert one by right-clicking on the root subform (or any other subform) and selecting the
Insert Script Object item.



Once that was done, the script on the Enter event of the text field was changed to this:



event.target.getField(ScriptObject.GetAcroFormSOMExp(this)).doNotScroll = true;


The beauty is that once the script object is setup, you can place this script on any field inside any number of nested subforms and it'll automatically restrict the field's value to that which its visual extent can contain.



Stefan

Adobe Systems

Avatar

Former Community Member
You already have your answer, but I thought I'd chime in with (what may be) a simpler solution.



(I didn't look at the sample pdf - for reference)



A text field can restrict the number of characters by setting the character limit to whatever fits inside that field. Once the user reaches that limit, they cannot enter any more text. No scroll bars, no truncated text.



In Designer > Object/Limit Length/Max characters

Avatar

Former Community Member
John's suggestion is a good one -- and simpler too! The only thing is that you have to play with the Max Characters and Default Value properties to figure-out what the maximum limit is. There's also the problem of font kerning where if you're not using a fixed-width font (like Lucida Console or Courier New), you'll never be able to set the correct limit because the space required for 100 characters in Times New Roman can vary significantly depending on the characters entered.



The idea with my solution is to put the onus on Acrobat to figure all this out because with its doNotScroll property, it's able to consider all types of fonts regardless of their kerning.



If you're using a fixed-width font, there's a tool in Designer 7.1 that'll make it easier to set the right Max Character limit (if you choose to use that method to restrict the length of text that can be entered into the field): In the Tools|Options dialog, there's a "Wizards and Tips" tab. On that tab, there's a section called "Show In-place Warning Markers" in which there's a check box labelled, "When Value Area is Too Small". If you turn this on, set your field's font to a fixed-width font (e.g. "Courier New") and set a Max Character limit, a marker icon will appear on the field if the field's visible area isn't big enough to contain the maximum number of characters that could be entered into the field. At this point, you can either play with the Max Character property or play with the field's width and/or height until the marker goes away and you can be confident that the field will have enough space to fit all characters set by the Max Character limit.



Note that this special marker may affect Designer's performance if you have a lot of fields on your form. This is because the calculations required for the test are quite "expensive". As such, I suggest that once you're done adjusting your field, you turn that specific marker off (by using the Tools|Options dialog again).



Stefan

Adobe Systems

Avatar

Former Community Member
Note that John's solution, while simple for single line fields, fails to account for fields where the multiline property is checked, thereby allowing a user to insert a carriage return several times in the field

while

they

are

typing

(like

this)

.



:-)

Avatar

Former Community Member
This really works great, especially for the forms that I work on. But what I was wondering is what field in the script besides the textfield name need to be changed when you are working on another page. For example what would the script have to be if you were working on page 3, and the textfield 4. And you want that textfield to have scrolling disabled? I know this is probably going to be something simple but I just couldn't get it to work