Anyone have ideas for this one?
I'll take a stab, but I'm not sure what you're trying to accomplish here. So if the user pastes the string "ABCDE" into the first field, you want to have field1="A", field2 = "B", etc? What happens if they paste the string into one of the other fields? How do the characters get distributed?
Also, are all of the fields the same length, and what's the max length?
It would be nice if the string can always be distributed begining from the first textbox no matter where it's pasted within the rows of textboxes. Also each textbox can only hold a single character and they are all set up this way.
-Thanks in advance for taking a stab.
There are issues with this, but it can be done. Some of it will depend on you setting up your form correctly.
First, if the text fields are all set up to hold a max of 1 character, you can't use event.newText to get the pasted string, since newText returns the truncated text. Instead, you need to use event.fullText.
Second, the process becomes much easier if you name all of your text fields the same, with a suffix of the occurance of the field starting from zero. So: "Textfield0", "Textfield1", etc. I think you already headed down that path.
Third, make sure you truncate the pasted string so that the length is not greater than the number of text boxes. My example below uses the string.slice() method to truncate. This assumes that there are 8 text boxes, you would change the "8" in the slice method to whatever your count is.
Based on the above, you can use a loop in the else section to fill in the fields. The script is exactly the same for all text boxes since you're always starting the fill from the first textfield, so you can probably break this out into a global script method and eliminate duplicating the code.
var enteredText = xfa.event.fullText.slice(0, 8);
for (var i = 0; i < enteredText.length; i++)
xfa.resolveNode("TextField" + i.toString()).rawValue = enteredText.substr(i, 1);
There are other issues to deal with, depending on how your form is supposed to function. For example, you will probably want to clear out the remaining text fields if a string that is shorter than the number of text fields is pasted. That can be done with a small mod to the loop above.
I think you might also have a problem if the user pastes a string into a field that already contains a character. The fullText value will include that character plus the pasted text. You can check event.prevText and adjust the string if necessary.
Hopefully this will get you going.