0

Good morning,

First of all, thanks in advance for any help you might provide

I'll try and explain myself as clearly as possible:

I have a column of some 30ish equal text fields, with an unmodifiable width and height in a form. The users will have two options when inputting text into the text fields:

a) Type word by word

b) Copy from another souce a chunk of text and paste it into the text field.

Now, what I want is to have two different options for the form to auto-tab to the next text field if the first one has been filled.

These are the two options I have tried up to now, which both work when used on their own, but won't work together:

a) Custom Keystroke script for, lets say, Field.0:

if (event.fieldFull) {
     this.getField("Field.1").setFocus();
}

b) Custom on-blur script for Field.0:

var temp = new Array();
temp = this.getField("Field.0").value.split(' ');
var rest = "";
ini = temp[0] + ' ';
var charsRead = temp[0].length + 1;
var index = 1;
while ((charsRead + temp[index].length) < 110){
    ini = ini + temp[index] + ' ';
    index++;
    charsRead = charsRead + temp[index].length + 1;
}
for (var i=index ; i < temp.length-1 ; i++){
    rest = rest + temp[i] + ' ';
}
this.getField("Field.0").value = ini;
this.getField("Field.1").value = rest;
this.getField("Field.1").setFocus();

As you might probably have noticed, I am no expert (not even close to one...) scripter, so the code might be inefficient or repetitive.

What the script does is: Store the words of the chunk pasted into an array (so as not to split the text in the middle of a word), and copy the first fitting words up to 110 chars (an arbitrary number which sometimes is too little and sometimes too much), and then takes the rest of the words in the array and pastes them into the next field.

When the user tabs out of the Field.0 the focus is set to Field.1. If the text is still too long, when he tabs out of Field.1, the focus is set to Field.2 with the second remainder of the text pasted into it. So, all he has to do is Ctrl+V and TAB, TAB, TAB until all the text has occupied the necessary fields.

Now, for the solution to point a), Scrolling Long Text has to be disabled, but, it is necessary for the script used to solve problem b).

What I am looking for is a way of, independently on how the user has inputted text, to auto-tab WHEN THE FIELD IS FULL. And by full I mean that the text has reached THE END OF THE VISIBLE AREA.

Be it while typing out the text (I suppose it'd has to be with a keystroke script) or when pasting a long phrase (with an on-blur, since keystroke doesn't work here).

Sorry for the long post and thank you once more for the help.

BTW: Using Adobe Acrobat X Pro.

JSG_ESP
  • 45
  • 1
  • 7

1 Answers1

1

If you have a monospaced font, you can determine how many characters fit in a text field. Break the pasted text up into chunks of that size, then distribute these chunks over the fields. So, using the chunk function found here:

//(On paste)
var brokenUpString = pastedString.chunk(maxInputLengthPerField);
for(var i = 0; brokenUpString[i]; i++){
    fields[i]value = brokenUpString[i]
}

Now, if you want to move the cursor to the next text field when a user is typing, something like this may work:

//(On key up)
var currentField = 0;
if(fields[currentField].value.length == maxInputLengthPerField){
    currentField++;
    fields[currentField].setFocus();
}

The problem is that it's "hard" to detect how many characters are entered when a user keeps a button pressed, but you could just take the whole string, break it up, and distribute it over the fields, if that happens.

(chunk() function from the link:)

String.prototype.chunk = function(size) {
    return [].concat.apply([],
        this.split('').map(function(x,i){ return i%size ? [] : this.slice(i,i+size) }, this)
    )
}
Community
  • 1
  • 1
Cerbrus
  • 70,800
  • 18
  • 132
  • 147
  • First off, thanks for the response. However, using a monospaced font is preferably not an option. This is due to the homogeneity with the rest of the PDF document, which uses a non-monospaced font. It worse comes to worst, I'll end up using one, but I'd like to avoid it for now. I have just seen that in Acrobat 8.0 there was a "checkbox" in the text field options where you could limit the size to the visible area. I'd like to know what function is called when the checkbox is ticked. That could prove to be a viable solution. – JSG_ESP Nov 20 '12 at 10:22
  • I'm afraid I can't help you with Acrobat-specific functions, nor do I know of any way to detect if a string is overflowing it's field (And at what index). – Cerbrus Nov 20 '12 at 10:37